Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-21-2012, 04:30 PM   PM User | #1
bigcasey123
New Coder

 
Join Date: Feb 2012
Posts: 95
Thanks: 1
Thanked 5 Times in 4 Posts
bigcasey123 is an unknown quantity at this point
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

Quote:
66: form.engine.onchange = function( )
67: {

Last edited by bigcasey123; 09-21-2012 at 08:51 PM..
bigcasey123 is offline   Reply With Quote
Old 09-21-2012, 05:01 PM   PM User | #2
DaveyErwin
Regular Coder

 
Join Date: Aug 2010
Posts: 809
Thanks: 12
Thanked 168 Times in 166 Posts
DaveyErwin is on a distinguished road
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..
DaveyErwin is offline   Reply With Quote
Old 09-21-2012, 05:40 PM   PM User | #3
raja.krishnan3
New to the CF scene

 
Join Date: Sep 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
raja.krishnan3 is an unknown quantity at this point
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>
raja.krishnan3 is offline   Reply With Quote
Old 09-21-2012, 05:55 PM   PM User | #4
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
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 :
http://www.codingforums.com/showthread.php?t=82672
http://www.codingforums.com/showthread.php?t=2090
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 09-21-2012, 07:43 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 09-21-2012, 08:41 PM   PM User | #6
bigcasey123
New Coder

 
Join Date: Feb 2012
Posts: 95
Thanks: 1
Thanked 5 Times in 4 Posts
bigcasey123 is an unknown quantity at this point
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>
bigcasey123 is offline   Reply With Quote
Old 09-21-2012, 08:46 PM   PM User | #7
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
oh, I see the problem. Trailing comma. Delete the comma at the end of this line:
Code:
"ask" : { "logo" : "images/ask.png", "code" : doAsk },
xelawho is offline   Reply With Quote
Old 09-21-2012, 08:48 PM   PM User | #8
bigcasey123
New Coder

 
Join Date: Feb 2012
Posts: 95
Thanks: 1
Thanked 5 Times in 4 Posts
bigcasey123 is an unknown quantity at this point
Yaaa thanks xelawho

Last edited by bigcasey123; 09-21-2012 at 08:50 PM..
bigcasey123 is offline   Reply With Quote
Old 09-21-2012, 08:49 PM   PM User | #9
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
No, it's the comma. Works fine in IE. You wouldn't even get that error if you had javascript turned off.
xelawho is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:11 AM.


Advertisement
Log in to turn off these ads.