I have a page that dynamically creates multiple forms and js code (20+). When the user selects an item from a select dropdown, (change trigger) it posts data to another script via ajax.
Form names are like: form1, form2, form3, etc.
Is there a way to specify which field input data to pass based on which select was changed?
For example, with: adId: $('input[name$="ad_id"]').val() Need to specify which form to select from to obtain the desired data.
If changeCat2 select changed, pass the ad_id value from that specific form (form2).
EDIT - More code:
<script type="text/javascript">
$(document).ready(function() {
$('select.changeCat2').change(function(){
$.ajax({
type: 'POST',
url: 'cat_update.php',
data: {selectFieldValue: $('changeCat').val(), mlsId: $('input[name$="mls_id"]').val(), adId: $('input[name$="ad_id"]').val(), imageId: $('input[name$="image_id"]').val(), photoUrl: $('input[name$="photo_url"]').val()},
dataType: 'html'
});
});
});
</script>
<form method="post" action="" name="form2">
<input type="hidden" name="mls_id" value="W7631557">
<input type="hidden" name="ad_id" value="107">
<select name="changeCat2">
<option value="Living Room">Living Room</option>
<option value="Dining Room">Dining Room</option>
<option value="Family Room">Family Room</option>
<option value="Den/Office">Den/Office</option>
<option value="Kitchen">Kitchen</option>
<option value="Exterior">Exterior</option>
<option value="Bedrooms">Bedrooms</option>
<option value="Bathrooms">Bathrooms</option>
<option value="Pool/Patio">Pool/Patio</option>
<option value="Great Room">Great Room</option>
<option value="Balcony/Porch/Lanai">Balcony/Porch/Lanai</option>
</select>
<input type="hidden" name="image_id" value="2">
<input type="hidden" name="photo_url" value="http://myimages/">
</form>