?
Solved

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

Posted on 2003-03-17
6
Medium Priority
?
7,829 Views
Last Modified: 2010-05-18
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
Comment
Question by:geezen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Accepted Solution

by:
ngrover earned 100 total points
ID: 8155172
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
 
LVL 30

Assisted Solution

by:third
third earned 100 total points
ID: 8155837
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
 
LVL 30

Expert Comment

by:third
ID: 8155856
if your parameter contains spaces, use

var path = unescape(document.location.search.substring(1).split('=')[1]);
0
 
LVL 4

Expert Comment

by:whammy
ID: 8156048
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
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10148652
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question