...

View Full Version : changing link based on variable



nluoma
02-24-2003, 05:25 PM
I need to add a value to a link, based on the value of a variable. (This is because my site is not allowed to use cookies.) I am passing this variable from one page to another by means of a function:
<script language="JavaScript"><!--
//this function will take a passed URL and add the ?db= segment.
//Do NOT call this for pages going to the correct Basic/Advanced pages.
function intercept(what) {
what.href += '?db=' + db; //adds the correct db scenario (?db=...) to the end of the URL
}
//--></script>

However, there are a few times where I need to add this to the URL itself--instead of basic/basic.htm I want the user to go to basic/basic_"valueofdb".htm.

I can't figure out how to do this! I can write code that will put the correct path into a variable, but cannot return this variable to the link.

ANy advice?

N

wyattwebb
03-24-2003, 07:09 PM
<script language="JavaScript"><!--
//this function will take a passed URL and add the ?db= segment.
//Do NOT call this for pages going to the correct Basic/Advanced pages.
function intercept(what,addToUrl)
{
// Check a boolean var if you want to add the db var to the href
if (addToUrl)
{
var vArr = split(what.href,"."); // Splitting up http://somthing.com/somthing.htm into an array.
var vFirstHalf = vArr(0) + "" + vArr(1) + "_" + db; // assuming there is a .com or something.
var vSecondHalf = vArr(2) ;
what.href = vFirstHalf + vSecondHalf;
}

what.href += '?db=' + db; //adds the correct db scenario (?db=...) to the end of the URL
}
//--></script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum