I have a search form that have multiple input types and I would like to get the values from the search form whenever user make a changes on the input.
The form is like this:
<form id="search">
<input type="hidden" name="cat[0][name]" value="cat1">
//select type input.
<select id="cat-0" name="cat[0][id]" >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="hidden" name="cat[1][name]" value="cat2">
<select id="cat-1" name="cat[1][id]" >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
//checkbox type input
<input type="hidden" name="cat[2][name]" value="cat3">
<label><input id="cat-2" type="checkbox" name="cat[2][id][]" value="1"> 1</label>
<label><input id="cat-2" type="checkbox" name="cat[2][id][]" value="2"> 2</label>
<label><input id="cat-2" type="checkbox" name="cat[2][id][]" value="3"> 3</label>
//radio type input
<input type="hidden" name="cat[3][name]" value="cat4">
<label><input id="cat-3" type="radio" name="cat[3][id]" value="1"> 1</label>
<label><input id="cat-3" type="radio" name="cat[3][id]" value="2"> 2</label>
<label><input id="cat-3" type="radio" name="cat[3][id]" value="3"> 3</label>
</form>
As you can see the input values are in multidimensional array. How do i get those values by javascript when user make a changes on either one of the input. All I wanted to do is create a search engine like this site .
The form is generated dynamically, thus I can't defined a fixed id/class for every field.
The js script should be something like this?
$('[id^=cat]').live('change', function(e) {
passing_data();
return false;
});
function passing_data() {
var getdata = $(':input[name="cat"]').val();//this i can't get it.
alert(getdata);
return false;
}
The passing_data() is the part i didn't get it, it will be used in ajax to perform search function.
Any idea?
serialize the formand send to server viaajaxand handle it all there ?