Reputation: 4469
I have tried to get value from select option in cakephp,Here is my code
echo $this->Form->input('division', array('type' => 'select',
id=>'my-select',
'options' => array('Dhaka' => 'Dhaka', 'Dinajpur' => 'Dinajpur','Others'=>'Others'),'selected' => 'Dhaka'));
Here is my js code
<script>
$(document).ready(function(){
$("#my-select").change(function() {
alert($('#my-select option:selected').html());
});
});
</script>
Problem is no any feed back given.I am enable to find error.Where is the problem ?
Upvotes: 0
Views: 1412
Reputation: 626
$(document).ready(function(){
$("#my-select").on('change',function(e){
var select_value = $(e.currentTarget).val();
alert(select_value);
});
});
Upvotes: 0
Reputation: 15403
Use .on() in jquery. Cakephp rendered dom elements dynamically.
$(document).on("change" , "#my-select" , function() {
alert($('#my-select option:selected').html());
});
Upvotes: 2