Reputation: 656
I have a piece of html code like the one below:
<div>
<div><input id='route' value='1'></div>
<div>
<select id='selID'>
...
</select>
</div>
</div>
Now, I want to get the value from the input once I select any option from select element I have tried something like this, but still with no succes:
$(document).on('change', '#selID', function (event) {
alert($(this).parent().siblings('div').children('input').val());
});
Could someone give me a solution? Thank you in advance!
Upvotes: 0
Views: 3292
Reputation: 4484
You can do it like this -
$("#selID").on('change', function(){
var $a = $(this);
if($a.val() != ""){
alert($a.parent().parent().find('input').val());
}
return false;
});
Fiddle: http://jsfiddle.net/vzmzu6zc/
Upvotes: 2