Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    96
    Thanks
    1
    Thanked 5 Times in 4 Posts

    Javascript not working on IE8??

    I keep getting this error "Expected identifier, string or number
    index.php line: 61"

    and here is my code

    Code:
    <script type="text/javascript">
    (function( )
      {
      function doGoogle( searchFor ) { this.location.href="https://www.google.com/search?q="+searchFor; }
      function doYahoo( searchFor ) { this.location.href="http://search.yahoo.com/search?p="+searchFor; }
      function doBing( searchFor ) { this.location.href="http://www.bing.com/search?q="+searchFor; }
      function doAsk( searchFor ) { this.location.href="http://www.ask.com/web?q="+searchFor; }
          var choices = {
              "google" : { "logo" : "images/google.png", "code" : doGoogle },
              "yahoo" : { "logo" : "images/yahoo.png", "code" : doYahoo },
    		  "bing" : { "logo" : "images/bing.png", "code" : doBing },
    		  "ask" : { "logo" : "images/ask.png", "code" : doAsk },
    		 
          }
    	  
    	  var form = document.getElementById("theForm");
          var engineCode = null;
    
          form.engine.onchange = function( )
          {
              var choice = this.value;
              if ( choice == "" ) return; // "choose one" selected?
              document.getElementById("theImage").src = choices[choice].logo;   
              engineCode = choices[choice].code;
         }
         
         form.doit.onclick = function( ) 
         {
             if ( engineCode != null )
             {
                engineCode( form.search.value );
             }
         }
      }
    )( ); // self-invoke anonymous function
    </script>

    This is line 67

    66: form.engine.onchange = function( )
    67: {
    Last edited by bigcasey123; 09-21-2012 at 08:51 PM.

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    945
    Thanks
    19
    Thanked 205 Times in 203 Posts
    among other problems
    you may have, this code
    must not be executed before
    window.onload(or body.onload)
    has fired, also you must
    have a form element
    with the name (not id)
    "engine"
    Last edited by DaveyErwin; 09-21-2012 at 05:05 PM.

  • #3
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi the below script is not working form me. Please any one help to find the issue.

    <!DOCTYPE html>
    <html>

    <body>

    <form method="post" name="input1" onsubmit="return validateinputs()">
    <STRONG>Question 1</STRONG>: <br />
    <input type="radio" name="q1" value="male" /> choice1<br />
    <input type="radio" name="q1" value="female" /> choice2<br />
    <STRONG>Question 2</STRONG>: <br />
    <input type="radio" name="q2" value="male" /> choice1<br />
    <input type="radio" name="q2" value="female" /> choice2<br />
    <STRONG>Question 3</STRONG>: <br />
    <input type="radio" name="q3" value="male" /> choice1<br />
    <input type="radio" name="q3" value="female" /> choice2<br />
    <input type="submit" value="Submit" />
    </form>

    <script language="JavaScript" type="text/javascript">
    <!-- Copyright 2001, Sandeep Gangadharan -->
    <!-- For more free scripts go to http://sivamdesign.com/scripts/ -->

    <!--
    function validateinputs() { // modify the script below to match your needs
    var q1_ans, q2_ans, q3_ans;
    for (var i=0; i < document.input1.q1.length; i++)
    {
    if (document.input1.q1[i].checked)
    {
    q1_ans = document.input1.q1[i].value;
    }
    }
    for (var i=0; i < document.input1.q2.length; i++)
    {
    if (document.input1.q2[i].checked)
    {
    q2_ans = document.input1.q2[i].value;
    }
    }
    for (var i=0; i < document.input1.q2.length; i++)
    {
    if (document.input1.q3[i].checked)
    {
    q3_ans = document.input1.q1[i].value;
    }
    }
    if(q1_ans=="male" && q2_ans=="male" && q3_ans=="male")
    {
    window.location = "allmale.html";
    return false;

    }

    }
    // -->
    </script>

    </body>
    </html>

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by raja.krishnan3 View Post
    Hi the below script is not working form me. Please any one help to find the issue.......
    Please read the posting rules :
    Please format code in your posts using the [code][/code] tag!
    MUST READ- How to post a JavaScript question!

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,732
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    raja.krishnan3 - please do not hijack someone else's thread. Prefer to start a new thread of your own.

    Before posting again please read and comply with the forum rules and posting guideines.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    New Coder
    Join Date
    Feb 2012
    Posts
    96
    Thanks
    1
    Thanked 5 Times in 4 Posts
    Quote Originally Posted by DaveyErwin View Post
    among other problems
    you may have, this code
    must not be executed before
    window.onload(or body.onload)
    has fired, also you must
    have a form element
    with the name (not id)
    "engine"
    This code isn't executed before window.onload (or body.onload) and i had a name "engine" not id. Here is my body code

    Code:
    <body>
     
     
     
     
     
     <div id="header">
     <b>  &nbsp
          &nbsp
     <a href="index.php" class="links" style="color:white">Web</a> &nbsp &nbsp
     <a href="image.php" class="links">Images</a> &nbsp &nbsp
     <a href="videos.php" class="links">Videos</a> &nbsp &nbsp
     <a href="adult videos.php" class="links">Adult Videos</a> &nbsp &nbsp
     </b>
     </div>
     
     
     <img id="theImage" name="theImage" />
     
    <form id="theForm" onSubmit="return doSearch()" name="theForm">
    <input name="search" id="searchbox"/>
    <br/>
    Use what engine:
        <select name="engine">
    	<option> Choose one</option>
        <option value="google">Google</option>
        <option value="yahoo">Yahoo</option>
        <option value="ask">ask</option>
    	<option value="bing">bing</option>
        </select>
    <br/>
    <br />
    <center><input type="button" value="Search!" name="doit"/></center>
    </form>
    
    <script type="text/javascript">
    (function( )
      {
      function doGoogle( searchFor ) { this.location.href="https://www.google.com/search?q="+searchFor; }
      function doYahoo( searchFor ) { this.location.href="http://search.yahoo.com/search?p="+searchFor; }
      function doBing( searchFor ) { this.location.href="http://www.bing.com/search?q="+searchFor; }
      function doAsk( searchFor ) { this.location.href="http://www.ask.com/web?q="+searchFor; }
          var choices = {
              "google" : { "logo" : "images/google.png", "code" : doGoogle },
              "yahoo" : { "logo" : "images/yahoo.png", "code" : doYahoo },
    		  "bing" : { "logo" : "images/bing.png", "code" : doBing },
    		  "ask" : { "logo" : "images/ask.png", "code" : doAsk },
    		 
          }
    	  
    	  var form = document.getElementById("theForm");
          var engineCode = null;
    
          form.engine.onchange = function( )
          {
              var choice = this.value;
              if ( choice == "" ) return; // "choose one" selected?
              document.getElementById("theImage").src = choices[choice].logo;   
              engineCode = choices[choice].code;
         }
         
         form.doit.onclick = function( ) 
         {
             if ( engineCode != null )
             {
                engineCode( form.search.value );
             }
         }
      }
    )( ); // self-invoke anonymous function
    </script>
    
     </body>

  • #7
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,772
    Thanks
    55
    Thanked 518 Times in 515 Posts
    oh, I see the problem. Trailing comma. Delete the comma at the end of this line:
    Code:
    "ask" : { "logo" : "images/ask.png", "code" : doAsk },

  • #8
    New Coder
    Join Date
    Feb 2012
    Posts
    96
    Thanks
    1
    Thanked 5 Times in 4 Posts
    Yaaa thanks xelawho
    Last edited by bigcasey123; 09-21-2012 at 08:50 PM.

  • #9
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,772
    Thanks
    55
    Thanked 518 Times in 515 Posts
    No, it's the comma. Works fine in IE. You wouldn't even get that error if you had javascript turned off.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •