Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

passing a variable through an href statement

Posted on 2000-02-28
6
Medium Priority
?
283 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
ID: 2567168
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
ID: 2567604
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
ID: 2567609
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
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!

 
LVL 8

Accepted Solution

by:
xabi earned 75 total points
ID: 2567911
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
ID: 2569692
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
ID: 2570207
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

Technology Partners: 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!

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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

810 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