Reputation: 156
i made drop down list with help of select jquery
echo $this->Form->input('Category',
array(
'data-rel' =>'chosen',
'style' => 'width:220px; margin-bottom:10px',
'placeholder' => 'Select Category',
'empty'=>'Select',
'id'=>'ProductCategoryId',
array('class'=>'required')
));
now i'm trying to retrieve value onchange i tried following code to get value and text. (my basic purpose is to get value)
<script>
$(document).ready(function () {
alert($("#ProductCategoryId option:selected").text());
alert($('#ProductCategoryId').val());
</script>
may be there are many answer of this question already on SO, but those did't resolve my problem.
Upvotes: 1
Views: 4496
Reputation: 24638
Missing });
at the end, and you do need to listen to the change
event.
Try this instead:
$(document).ready(function () {
$('#ProductCategoryId').on('change', function() {
alert( $('option:selected', this).text() );
alert( $(this).val() );
});
});
Upvotes: 2