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:

    <td>
      <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>
        <?}?>
      </select> 
    </td>
    <td>
      <span style="color: #898989;">Subcategories</span>
      <br />
      <select  name="sub_cat" style="width: 200px;" id="prod_subcat_2">
      </select> 
    </td>


function get_sub_cat(id, select_id){
$.ajax({
   type: "POST",
   url: "<?=base_url()?>admin/product/get_sub_cat/"+id,
   data: "",
   success:function (option_list) {
     $("#prod_subcat_"+select_id).children().remove();
     $('#prod_subcat_'+select_id).append(option_list);
   }
 });
}

      

+3


source to share


4 answers


Items are <option>

onclick

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



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

      

+4


source


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 http://support.google.com/chrome/bin/answer.py?hl=en&answer=114662

+1


source


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.

0


source


You need to add some quotes:

get_sub_cat(\"<?=$item['id']?>\",2)

      

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

<script>
   // your javascript
</script>

      

0


source