I am trying to implement this search builder for my application http://www.ncbi.nlm.nih.gov/pubmed/advanced
This is what I have so far. Created a HTML page with JS function to dynamically add/remove multiple fields with unique name ID for each input. Attempted, to automatically populate query box as the user types in or selects input fields. Something similar to this example http://jsfiddle.net/Dd3ee/ However, I could not complete the task, as I could not understand how to pass multiple ID. Any help is appreciated. Thank you
<script type = "text/javascript">
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initial text box count
var counter = 1;
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields) { //max input box allowed
x++; //text box increment
var myfields = ' " . str_replace("r", " ", str_replace("n", " ", "<div>
<select name="boolean_box_'+x+'"> <option> AND </option>" . my_func($boolean_value) . "</select>
<select name="field_box_'+x+'"> <option disabled>Please select </option>" . my_func($searchable_fields) . "</select> <input type="text" name="text_box_'+x+'" value="" size="50"
maxlength="100">")) . "<button type="button" class="remove_field">-</button></div>';
$(wrapper).append(myfields); //add input box
// Set the counter value in hidden input total_fields
$('input[name="total_fields"]').val(x);
// populate the query box
$(#text_box_'+x+').bind('keypress blur', function() {
$('#query_box').val($(#text_box_'+x+').val());
});
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x-- ;
})
});
</script>
Expected output after concatenation is a string within double quotes as below.
"ROSS[All Fields] AND Mosquitoes [Abstract] AND Prevention [Title]"
