• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7863
  • Last Modified:

javascript request.querystring, how can I get it to work client-side?

I have a page with thumbnail pics and I want those to link to just one page that I can PicViewer.htm so that I don't have to make separate pages for all of the main pics.

This is the code that I have on the thumbnail page:

<script language="javascript" type="text/javascript">
<!--
function popup(path)
     {
          window.open("PicViewer.htm?Path="+path,'','toolbar=yes,location=yes,directories=no,status=no,menubar=yes,scrollbars=no,resizable=no,width=540,height=400,top=100,left=100');
     }
// -->
</script>
<a href="javascript: popup('Images/tn_wedding20004.jpg')"><img src="Images/tn_wedding20004.jpg" width="150" height="100" border="0"></a>

That part works fine.  It's when I go to my PicViewer page, nothing shows up.  When I tested the variable, it shows up 'undefined'.
Here is the code for my PicViewer page:

<script language="javascript" type="text/javascript">
<!--

var path = Request.QueryString("Path");
document.write("<img src="+path+" width=512 height=341>");
// -->
</script>

I thought that this would be easy but I'm having a hell of a time getting it to work.  Thanks in advance.
0
geezen
Asked:
geezen
2 Solutions
 
ngroverCommented:
I've never seen a Request object in javascript.  

What you need to do is get the document.location.href value and parse it for the argument you want.  

An ideal method is the String.split() function.  It works kind of like a StringTokenizer in java.  You pass it a delimiter and get back an array of strings broken up from the original based on the delimiter.

So, if your href is HTTP://somelocation.html?path=test.gif&name=joe

you can get the value of path by doing this:

String[] args1 = document.location.href.split("?");

Now you have everything before the ? and everything after it.

Next, you need to split AGAIN on the second result.

String[] pathArgs = args1[1].split("=");

in this case, pathArgs[0] should be "path" and pathArgs[1] should be "test.gif";

var path=pathArgs[1];

Now you can create your image tag with :

document.write("<IMG SRC=" + path + " width=512 height=341>");

You can even add the heights and width to your URL and do the same with those if your images are going to be different sizes.

Hope this helps.

Nate Grover
http://www.nategrover.com
0
 
thirdCommented:
do it like this,

var path = document.location.search.substring(1).split('=')[1];
alert(path);
document.write("<img src="+path+" width=512 height=341>");
0
 
thirdCommented:
if your parameter contains spaces, use

var path = unescape(document.location.search.substring(1).split('=')[1]);
0
 
whammyCommented:
Check this out:

http://www.solidscripts.com/querystring.htm?pic=mypicture.jpg&width=214&height=118

Source code readily available using "view source". Hope it helps.
0
 
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: ngrover {http:#8155172} & third {http:#8155837}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now