Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 1st, 2007, 03:31 AM
Authorized User
 
Join Date: Jan 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default expected ';'

hello guys ur help is needed again
<script language="javascript" >
function ReturnUrl()
{
var url=parent.location.href; (url shoud contain that -->Forms/iframe1.aspx?country=Lebanon)
var index=url.indexOf('=');
var country=url.substr(index,url.length));
alert(country);
if (strcmp(country,'Lebanon')
{
link="Iframe1.aspx";
}
if (strcmp(country,'Jordan'))
{
link="IframeJordan.aspx";
}
if (strcmp(country,'Syria'))
{
link="iframeSyria.aspx";
}
parent.location.href=link;
}
</script>


<input type="button" value="Back to Main2" onClick="ReturnUrl()" >

it tells me that i am missing a ';' in line 15 which starts at <script language="javascript" > and an ObjectExpected on the onClick="ReturnUrl();" ...
10x in advance.(1st script i write so if i have any syntax error feel free to tell me)

 
Old February 1st, 2007, 04:24 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii
Check it
1>var country=url.substr(index,url.length));
replace with
var country=url.substr(index,url.length);

2>if (strcmp(country,'Lebanon')
replace with
if (strcmp(country,'Lebanon'))

Hope this will hope you

Cheers :)

vinod
 
Old February 1st, 2007, 04:26 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Your code is missing a closing parenthesis, not sure if that's the problem, line numbers in error messages aren't always decipherable. I would have used the location.search property and the switch construct:
Code:
var sSearch = location.search;
var iIndex = sSearch.indexOf("country=");
if (iIndex > -1)
{
  var sCountry = sSearch.substr(9); //Test this!!!
  var sLink;
  switch(sCountry.toLowerCase())
  {
    case "lebanon":
      sLink = "iframe1.aspx";
      break;
    case "jordan":
      //other countries.
  }
  parent.location.href = sLink;

  }
}
The script tag should also use type="text/javascript" rather than the deprecated language attribute.

--

Joe (Microsoft MVP - XML)
 
Old February 1st, 2007, 05:28 AM
Authorized User
 
Join Date: Jan 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<script language="javascript" type="text/javascript" >
function ReturnUrl()
{
var url=parent.location.href;
var index=url.indexOf('=');
var country=url.substr(index+1,url.length);
alert(country);
if (country.toLowerCase()=='lebanon')
{
var link='Iframe1.aspx';
}
if (country.toLowerCase()=='jordan')
{
var link='IframeJordan.aspx';
}
if (country.toLowerCase()=='syria')
{
var link='iframeSyria.aspx';
}
parent.location.href=link;
}
</script>
...finally..10x guys






Similar Threads
Thread Thread Starter Forum Replies Last Post
expected Then Adam H-W Classic ASP Basics 6 April 17th, 2008 05:41 AM
Object Expected!! Apocolypse2005 Javascript 0 July 3rd, 2006 12:23 PM
too few parameters expected n desprate Access VBA 6 April 29th, 2005 06:33 AM
Expected 'Then' Adam H-W Classic ASP Basics 5 July 26th, 2004 02:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.