Why is javascript not working in chrome?

I write ajax on my page, to get subcategories in select option, depending on categories option list click. In all browsers it works good, i can see my request, response in browsers console... but in chrome functions even doesn`t call. Dou you know, in 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);
   }
 });
}

Why is javascript not working in chrome?

georg

207k48 gold badges295 silver badges375 bronze badges

asked Mar 13, 2012 at 11:45

Anton SementsovAnton Sementsov

1,1666 gold badges18 silver badges34 bronze badges

6

An <option> elements onclick is not universally supported, instead use an event of the parent <select>

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

answered Mar 13, 2012 at 11:58

1

1) If you run on local folder and not running on server, then chrome have security reasons not to run these type of javascript calls. There is multiple threads around stack overflow about running localy javascript ajax calls on chrome if thats the case.

2) Try your javascript with simple alert("hey"); to check if javascript is working or its the ajax.

3) If javascript works. Use google "Developer tools" ctrl+shift+i, set breakpoint on your javascript call and check what get passed as variable and wheres the problem.

4) If javascript dont work try this http://support.google.com/chrome/bin/answer.py?hl=en&answer=114662

answered Mar 13, 2012 at 12:10

rskujarskuja

5714 silver badges17 bronze badges

Try attaching an onchange event handler and getting the selected element from the select element passed into on the event. It probably doesn't make sense to attach event handlers to individual options.

answered Mar 13, 2012 at 11:57

Matt EschMatt Esch

22.4k8 gold badges51 silver badges51 bronze badges

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 a <script> tag ? the question doesnt show it

<script>
   // your javascript
</script>

answered Mar 13, 2012 at 11:57

ManseManse

37.5k10 gold badges82 silver badges108 bronze badges

0

I guess chrome had an update, but not none of the javascript in reddit is working anymore. It works in other browsers. It looks like its missing a bunch of functions. I've tried hard resetting the cache, clearing browsing history, you name it, but no luck. Here's a screenshot of some of the errors:

http://imgur.com/a/cvCUi

Why JavaScript is not working in my browser?

Go to the web browser menu click on the Customize and control Google Chrome. Next, select Settings and click on the Show advanced settings. Under Privacy click on the Content settings. Locate the JavaScript section and select Allow all sites to run JavaScript (recommended).

How do I get JavaScript to work in Chrome?

Activate JavaScript in Google Chrome.
Open Chrome on your computer..
Click. Settings..
Click Security and Privacy..
Click Site settings..
Click JavaScript..
Select Sites can use Javascript..

How do I update JavaScript in Chrome?

This guide will step you through the process of getting JavaScript enabled in Google Chrome..
Click the Chrome menu button. ... .
Click the "Settings" menu item. ... .
Search for the JavaScript settings. ... .
Click "Site settings" ... .
Click the JavaScript settings item. ... .
Change the JavaScript setting..

How do you unblock JavaScript?

Chrome.
Click the wrench icon on the toolbar..
Click Options > Under the Hood..
In the Privacy section, click Content settings..
Scroll to the JavaScript section and click Allow all sites to run JavaScript (recommended)..
Close the Options tab and refresh the browser..