siva siva - 4 months ago 17
jQuery Question

JQuery on dropdown list change is not working in codeigniter

I am new to code igniter and I have searched the following question in number of StackOverflow threads but none of them seem to solve my problem.

I have the following view code:

<select name="select1" id="select1">
<option value="0">None</option>
<option value="1">First</option>
</select>
<scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">

// Ajax post
$(document).ready(function() {
$("#select1").change(function(event) {
event.preventDefault();
var id = $(this).val();
jQuery.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "index.php/mycontroller/method",
dataType: 'json',
data: {id: id},
success: function(res) {

}
});
});
});
</script>


Ok when I change the drop down list selection nothing happens, which should actually call my controller method. Can you please help me resolve this problem?

Thanks

Answer

You are using <select> id as category

But In jquery you are calling $("#select1").change(function(event) like this .

You just need to change $("#select1").change(function(event) to

$("#category").change(function(event)