1

I made a last minute change to my code and realized the jQuery is not working in IE and Chrome, but in FF runs fine. I managed to change some of the existing jQuery to js, and it works fine in all browsers, however, the below jQuery fails to work in IE and Chrome.

I am hoping I don't need to change this code to pure JS, so hopefully there is a work around, any ideas what I am doing wrong?

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('#address').change(function() {
        $('#mycheckboxdiv').toggle();
    });
    $('#name').click(function() {
        alert("well hello there.");
    });

    $('#school').keyup(function(e) {
        if (e.which == 9)                                    
            alert("great school");
    });
});
</script>
</head>

<body>
<form name="myform" method="post" action="myform.php" id="myform">
<table>
<tr>
  <td><b>Name:</b></td>
  <td><input name="name" id="name" value="" type="text" size="20" maxlength="20"/></td>
</tr>
<tr>
<td valign="top">
<input name="address" value="NO" type="checkbox">  NO<br>
<input name="address" id="address" value="YES" type="checkbox">  YES</td>
</tr>
<tr id="mycheckboxdiv" style="display:none">
<td colspan="2"></td>
</tr>
</table>
</form>
</body>
</html>
flavian
  • 28,161
  • 11
  • 65
  • 105
NULL
  • 1,559
  • 5
  • 34
  • 60
  • To cut off any problems start with this: 1 - use if(e.which === 9) instead of "==" 2 - at the top use "language=text/javascript" instead of "javascript" only. The put the "debugger" keyword inside the jquery script and see whats going on – ExoticSeagull Apr 22 '13 at 13:15
  • 2
    are you using a secured website? I know chrome automatically blocks scripts when used non-secure links, but FF doesn't. – J. Ghyllebert Apr 22 '13 at 13:16
  • What exactly is the problem in IE or Chrome? Can you please describe the desired behaviour and what is not working? – Friederike Apr 22 '13 at 13:16
  • The problem I am having is, IE, Chrome shows javascript error on the lower tab, and it gives the line number; When I comment the jquery code line by line and try to debug it, the error is in the jquery code. which I can't comment out. – NULL Apr 22 '13 at 13:18
  • on what line error is exactly? – Bojan Kovacevic Apr 22 '13 at 13:20
  • I have commented out all the code and left this, and this is an error $(document).ready(function() {}); according to IE, Chrome. I get zero errors when the whole code is commented out. – NULL Apr 22 '13 at 13:24
  • the error says line 72, nothing else. all my other javascripts are working just fine, other than anything to do with JQUERY. basically, any jquery references is giving errors in IE, Chrome, maybe the jquery include I have is wrong? – NULL Apr 22 '13 at 13:35
  • 1
    please post full html code – Mahmoud Farahat Apr 22 '13 at 13:36
  • 2
    When you hit the error, see your **stack trace**, follow this to **your** code, then let us know what you found. – Lee Taylor Apr 22 '13 at 13:40
  • i posted full code, many thanks for your help. – NULL Apr 22 '13 at 13:43
  • You are referencing `http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js` on a site that is loaded via SSL: won't work in most browsers. Use a CDN with a SSL option (Google's CDN supports SSL) or host the libraries locally. – m90 Apr 22 '13 at 14:01

2 Answers2

1

Most browsers rely on type, not language to trigger the JavaScript interpreter. So if you put <script type="text/javascript"></script>, you don't even need to specify language. The language attribute has been deprecated for a while now.

See this question.

Put this instead of what you currently have:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

Also, for the HTTPS issue, use the following:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>

Or you can specify HTTPS directly:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
Community
  • 1
  • 1
flavian
  • 28,161
  • 11
  • 65
  • 105
  • thanks but still didn't solve the problem. Basically, IE, Chrome is refusing any JQUERY. why I don't know. – NULL Apr 22 '13 at 13:54
  • Yes I did. and still nothing. its faustrating, i guess i will have ot change my code to good old js. – NULL Apr 22 '13 at 13:56
  • Did you used prototype.js or any other JS function? and if its using $ then it might be conflict between those two javascript library. if that is the case then you can use jquery.noconflict() – rach Apr 22 '13 at 13:58
  • @Menew, its always recommended to save a local copy of js & reference from there, in case, "ajax.googleapis.com is down your site will also be affected. :) – Pranav Singh Apr 22 '13 at 14:13
0

I am repeating what J. Ghyllebert said before, is your website using https??

Please try downloading latest js file & save to local & reference it from local address within your website.

Pranav Singh
  • 17,079
  • 30
  • 77
  • 104