Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Window. Location for button click w/ session vars

Here's the code so far, and it says strWPID is not defined.
This is an .asp page:

Code:
if (!navigator.javaEnabled())
{
window.location = "javanotenabled.asp";
} else {
<%
strWPID = session("sessionWPID")
strDB = session("sessionDB")
strPC = session("sessionPC")
strCA = session("sessionCA")
strWPN = session("sessionWPN")
%>

window.location = "MainMenu.asp?WPID="+strWPID+"&DB="+strDB+"&PC="+ strPC +"&CA=" + strCA +"&WPN="+ strWPN;
//vername="+vername+"&verno="+verno;
}

...but it's not working..any suggestions?
It says javascript error of:
strWPN is not defined
[674 byte] By [bubberz] at [2007-11-11 7:58:21]
# 1 Re: Window. Location for button click w/ session vars
You're confusing server-side vs. client-side variables. They exist in entirely different places.

Here's what your code should look like:

window.location = "MainMenu.asp?WPID=<%=strWPID%>&DB=<%=strDB%>&PC<%=strPC%>&CA<%=strCA%>&WPN=<%=strWPN%>";
bschaettle at 2007-11-11 23:34:59 >
# 2 Re: Window. Location for button click w/ session vars
bschaettle,

Thanks...yeah, I eventually got that through my think skull on Thursday!

Thanks for the reply!
bubberz at 2007-11-11 23:35:54 >
# 3 Re: Window. Location for button click w/ session vars
...oops! I forgot something:
You should also use the URLEncode() method when building a URL. This will automatically replace blank spaces with %20 and all the other weird stuff that needs to be changed in a URL. Your window.location stmt would look like this:

window.location = "MainMenu.asp?WPID=<%=URLEncode(strWPID)%>&DB=<%=URLEncode(strDB)%>&PC<%=URLEncode(strPC)%>&CA<%=URLEncode(strCA)%>&WPN=<%=URLEncode(strWPN)%>";

Likewise, when accessing strings that have been passed in through a URL, you should decode them using URLDecode().
bschaettle at 2007-11-11 23:36:57 >