I got this script from here
$(document).ready(function() {
$('#choose').change(function(event) {
$.post('select-ajax.php', {
selected: $('#choose').val()
},
function(data) {
$('#update').html(data);
}
);
});
});
<form id='form'>
<div id="update"></div>
<select name='selected' id="choose">
<option value="test1">Test1</option>
<option value="test2">Test2</option>
<option value="test3">Test3</option>
</select>
</form>
and i want to use it with multi ple form and also want it change only in that form , can anybody help me to make the code just like this
$(document).ready(function() {
$('#choose').change(function(event) {
$.post('select-ajax.php', {
selected: $('#choose').val()
},
function(data) {
$('#update').html(data);
}
);
});
});
<form id='form'>
<div id="update"></div>
<select name='selected' id="choose">
<option value="test1">Test1</option>
<option value="test2">Test2</option>
<option value="test3">Test3</option>
</select>
</form>
<form id='form'>
<div id="update"></div>
<select name='selected' id="choose">
<option value="1">111</option>
<option value="2">222</option>
<option value="3">333</option>
</select>
</form>
Change it from using IDs, which must be unique to using classes, like this:
Then make your script find the elements relatively, like this:
I’m also using
.serialize()to serialize the<form>here, you can leave that out and use{ selected: $(this).value() }to pass only the<select>‘s value. This approach works for any number of forms in the page.