?
Solved

passing a variable through an href statement

Posted on 2000-02-28
6
Medium Priority
?
279 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
[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
 

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
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!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

649 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