My Javascript code is not working in chrome

I am writing ajax on my page to get the subcategories in the select option, depending on how the category option list is selected. In all browsers it works well, I see my request, response in the browser console ... but in chrome functions it doesn't even ring. Do you know what the problem is? Here is my code:

      <span style="color: #898989;">Main categories</span>
      <br />
      <select style="width: 200px;">
        <?foreach ($main_categories as $item){?>
        <option onclick="get_sub_cat(<?=$item['id']?>,2);return false;" value="<?=$item['id']?>"><?=$item['title']?></option>
      <span style="color: #898989;">Subcategories</span>
      <br />
      <select  name="sub_cat" style="width: 200px;" id="prod_subcat_2">

function get_sub_cat(id, select_id){
   type: "POST",
   url: "<?=base_url()?>admin/product/get_sub_cat/"+id,
   data: "",
   success:function (option_list) {



source to share

4 answers

Items are <option>


not universally supported, use the parent event instead<select>

$('#theselect').change(function() {
   alert( $(this).val() );




1) If you are running a local folder and not running on the server then chrome has reasons why you don't need to run these javascript calls. There are several threads around about running local javascript ajax calls on chrome, if so.

2) Try javascript with a simple warning ("hey"); to check if javascript or its ajax is working.

3) If javascript works. Use google "Developer Tools" ctrl + shift + i, set a breakpoint on your javascript call and check what is passed as a variable and there is a problem.

4) If javascript doesn't work try



Try attaching an onchange event handler and get the selected item from the select element passed to the event. It probably doesn't make sense to attach event handlers to individual parameters.



You need to add some quotes:



you need to send this parameter as a string.

Are you sure your JavaScript is in the tag <script>

? the question doesn't show it

   // your javascript