Using QueryString with JavaScript?

Results 1 to 2 of 2

Thread: Using QueryString with JavaScript?

  1. #1
    Big Mac Guest

    Default Using QueryString with JavaScript?

    How would I use the querystring in conjunction with JavaScript if the Javascript is used to open a new window? Here is the code:<BR><BR>&#060;script&#062;<BR>function popupHelp() {<BR>var newWindow ="help.asp", "Help","scrollbars,height=450,width=520");<BR>newW indow.focus()<BR>}<BR>&#060;/script&#062;<BR><BR>&#060;a href="help.asp" onClick="popupHelp(); return false"&#062;Help&#060;/a&#062;<BR><BR>In my help.asp, I would like to know which page called help.asp so that I could show the appropriate help. An easy solution would be to have a different help file for each, but I was wondering if I could have just one help file.<BR><BR>Thanks in advance.<BR>

  2. #2
    David Mann Guest

    Default Solution

    Here you go: <BR><BR>You have everything right, but you just need to add one thing to your new Window object:<BR><BR>&#060;script&#062;<BR>function popupHelp() {<BR>var newWindow ="help.asp?helpItem=1", "Help","scrollbars,height=450,width=520");<BR>newW indow.focus()<BR>}<BR>&#060;/script&#062;<BR><BR>&#060;a href="help.asp" onClick="popupHelp(); return false"&#062;Help&#060;/a&#062;<BR> <BR> <BR>In the example above, I merely added in the ?helpItem=1 query string, which will be passed. In your help.asp, you can parse out the help items and dynamically assign each index the appropriate help text by using, say, a select case code block:<BR><BR>&#060;%<BR>Select Case Request.QueryString("helpItem")<BR><BR>Case "1"<BR> "You should re-boot your machine."<BR><BR>Case "2"<BR> "You should reformat your HDD."<BR><BR>Case "3"<BR> "You should call tech support."<BR><BR>Case Else<BR> "No help found for that item."<BR><BR>End Select<BR>%&#062;<BR><BR><BR>Now the only thing left to address is how you pass the helpItem to begin with to the JavaScript. The EASIEST way would be to pass the index to the actual function, but I&#039ll leave that part up to your creative talents! =) <BR><BR>Good luck, and I hope this helps!<BR><BR>Sincerely,<BR> --David<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts