Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change window.location= according to variable 2

Status
Not open for further replies.

garty

IS-IT--Management
Feb 22, 2001
40
0
0
GB
HELP!! I am a VB programer that has been 'Thrown in at the deep end' to get a web server working with asp/javascript elements and I am having to scavange code from various sources which is not fitting together. Here is my problem...


I have a web page that has various buttons(in javascript) that hyperlink to a page with a variable which (naturally) changes according to which button is pressed.

eg button 1 gives button 2 gives
This works fine. What I am having problems is that I then want to forward the user onto a different page depending on which button they have pressed.

If the clicked on button 1 they should go to , and button 2 should go to
I am using this at the top to read in the refer code

<%Option Explicit%>
<%
dim referree
referree = Request.QueryString(&quot;referree&quot;)
session(&quot;referree&quot;) = referree
%>

which puts it as a session variable named referree. Then in the <HTML> section I have this code which sets up the function nextpage()

<head>
<meta http-equiv=&quot;Content-Language&quot; content=&quot;en-gb&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<script language=&quot;JavaScript&quot;>
<!--
function nextPage(){
var sReferree, sDestination
sReferree==Request.QueryString(&quot;referree&quot;)
if (sReferree==&quot;1&quot;){
sDestination == ;
}
if (sReferree==&quot;2&quot;){
sDestination == ;
}
var nextAddr = &quot;window.location=sDestination;&quot;;
setTimeout(nextAddr,100);
}
//-->
</script>

Finally in the <BODY> section I have

<body onLoad=&quot;nextPage();&quot;>

to call the function.

Can anyone tell me where I am going wrong.

Eternally gratefull
Garty
 
Ok change:

if (sReferree==&quot;1&quot;){
sDestination == ;
}
if (sReferree==&quot;2&quot;){
sDestination == ;

To:

if (sReferree==&quot;1&quot;){
sDestination = ;
}
if (sReferree==&quot;2&quot;){
sDestination = ;

In JavaScript use &quot;==&quot; (double equal sign) to compare use &quot;=&quot; (single equal sign) to assign.

&quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
there seems to be a few more errors in your original code...

this should work:
Code:
function nextPage(){
	var sReferree, sDestination;
	try {
		sReferree = location.search.match(/referree=\d+/)[0].split(&quot;=&quot;)[1];
		
		if (sReferree == &quot;1&quot;){
			sDestination = &quot;[URL unfurl="true"]http://dom1.com/page.asp?new-refer-code-1&quot;;[/URL]
		}
		if (sReferree == &quot;2&quot;){
			sDestination = &quot;[URL unfurl="true"]http://dom2.com/page.asp?new-refer-code-1&quot;;[/URL]
		}
		
		window.location = sDestination;
	} catch(e) {}
}


is there a reason why you were trying to redirect after 100ms?
setTimeout(nextAddr,100);

I've written it to redirect immediately.





========================================================================== =========================================================
while (!succeed) try();
-jeff
 
Heeeellllpppp!!!! AAAaaaarrrrrgggghhhhh!!!

Guess what - It still does not seem to want to work.

Thanks MrGreed and jemminger for your posts but it does not work. I tried both your suggestions but nothing.

Below is my complete code. Even with the bogus domain name it should still TRY to transfer it to dom1.com, but all I get is &quot;Done, with Errors&quot; or Done. Error says Line 30, Char 1 Object Expected.

My IE address bar is reading the following...

Please help, I am a desperate person who sees the window ledge as &quot;very inviting&quot; at the moment. Thanks

<%Option Explicit%>
<%
dim referree
referree = Request.QueryString(&quot;referree&quot;)
session(&quot;referree&quot;) = referree
%>
<html>
<head>
<meta http-equiv=&quot;Content-Language&quot; content=&quot;en-gb&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<script language=&quot;JavaScript&quot;>
<!--
function nextPage(){
var sReferree, sDestination;
{
sReferree = location.search.match(/referree=\d+/)[0].split(&quot;=&quot;)[1];

if (sReferree == &quot;1&quot;){
sDestination = &quot; }
if (sReferree == &quot;2&quot;){
sDestination = &quot; }

window.location = sDestination;
} catch(e) {}
}
//-->
</script>
<title>Transferring...</title>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;styles.css&quot;>
</head>
<body onLoad=&quot;nextPage();&quot;>
<p>One Moment Please, Transferring you to your destination...</p>
</body>
</html>
 
Please note on last post that the 'sDestination = ' lines are showing double semicolons at the end of the line which are NOT in my code. I have single semi-colons. Not sure why it came out as 2!

Incidentally, the destination of this page (who I do not want to reveal as they are a third party) want the following as the destination URL


Is this going to cause problems/Has this been the cause of the problems due to the fact that it has an = sign.

In other words, when we try to assign the value to sDestination how are we going to get the = sign in? Or is it fine because it is within &quot;&quot; marks.

ie
sDestination = &quot;
 
STOP PRESS

Close those windows and turn the locks!!!

I have it sussed now.

I was missing 'try' from the line before
sReferree = location.search.match(/referree=\d+/)[0].split(&quot;=&quot;)[1];

It now seems to be working fine.

&quot;Stars all round&quot;. MrGreed for your speedy response and definition of = and ==

Jeff (jemminger) for your coding.

Thanks again Guys


Garty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top