Solved

passing a variable through an href statement

Posted on 2000-02-28
6
270 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Accepted Solution

by:
xabi earned 25 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

863 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

22 Experts available now in Live!

Get 1:1 Help Now