Solved

passing a variable through an href statement

Posted on 2000-02-28
6
269 Views
Last Modified: 2008-03-17
How do I pass a javascript variable when I use an HREF statement?  I need to pass a variable "instr" to a cgi.
example
HREF=("/bin/file.cgi?instr="+instr)

I tried that and the value seems to get lost.
0
Comment
Question by:kllewelyn
6 Comments
 

Expert Comment

by:jimmyontour
Comment Utility
Are you doing this

<a href="/bin/file.cgi?instr=some_instruction">

or this

<script language="javascript">
document.location="/bin/file.cgi?instr="+instr;
</script>
0
 
LVL 4

Expert Comment

by:jkunal
Comment Utility
Try this...........

<%
x="/bin/file.cgi?instr=" & instr
%>

<A href="<%=x%>">Lets Go</a>

Works for me, Give it a try........

;->
0
 
LVL 8

Expert Comment

by:jbirk
Comment Utility
If you want it to be from an html link, you can combine the two methods that jimmyontour mentioned like so:

<A HREF="JavaScript:void(0);" onClick="goto(); return false;">jkashd</A>

<script language="javascript">
<!--
function goto()
{// any manipulation of variable instr here...
 document.location="/bin/file.cgi?instr="+instr;
}
// -->
</script>


-Josh
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 8

Accepted Solution

by:
xabi earned 25 total points
Comment Utility
This is what you must do:

<a href="javascript:document.location='/bin/file.cgi?instr=' + escape(instr)">the link</a>

xabi

PS: None of the above used escape and this is important.
0
 
LVL 1

Author Comment

by:kllewelyn
Comment Utility
basically I'm doing this based on a click

top.or_main.location.href=("/cgi-bin/or_image.cgi?instr="+top.or_vars.instr)

I want the or_main frame to be replaced with the or_image.cgi. The cgi needs to receive the instr variable and do a database select statement.  I have an alert right before I use the above statement, and the variable equals what it should, but when it gets to the cgi, the passed value is blank.  I must not be passing it correctly.
0
 
LVL 8

Expert Comment

by:jbirk
Comment Utility
Which frame is this being called from?  If it's "or_vars", then you don't need to reference the variable via top.or_vars...  It should work though.  Are you sure that or_vars is the correct frame name?  Is instr a variable in that frame or an object like a text field?  It's a text field it should be:
top.or_vars.instr.value

-Josh

P.S. It is important to escape this variable as xabi said.  I had forgotten about that...  If it's not escaped, the value sent to the cgi may not be correct ly if invalid characters like spaces are used in instr.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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-…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now