I am trying to get the value of a parent when clicking a button:
The HTML part:
<td>
<select>
<option value='2' >Administrator</option>
<option value='3' selected='selected'>Webmaster</option>
<option value='4' >Editor</option>
<option value='5' >Journalist</option>
</select>
</td>
<td>
<div class='save'>Save</div>
</td>
The JavaScript part:
$('.save').click( function() {
level = $(this).parent('select option:selected').val();
alert(level);
});
The manner in which you are getting the selected value is incorrect. You should instead do:
level = $(this).parent().prev().find('select option:selected').val();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With