I have an array of drop-downs in a page, one for each row in a list of records. I need to update a DIV's content in the row of the drop-down that triggers each change event.
Something like this:
<div class="price"></div>
<select id="plan[]" name="plan[]" class="sel">
<option value="0" selected="selected">None</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
$(function() {
$('#plan').change(function(){
$(this).prevAll('.price:first').html('foo bar');
});
});
The change event never fires, what am I missing? Here's a fiddle to test
name="plan[]"because it will eventually be submitted to a PHP script and needs to be an array. You don't have to setid="plan[]"as PHP will not use it. Just setid="plan"and your jQuery will work fine.