Link to home
Start Free TrialLog in
Avatar of kllewelyn
kllewelyn

asked on

passing a variable through an href statement

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.
Avatar of jimmyontour
jimmyontour

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>
Try this...........

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

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

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

;->
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
ASKER CERTIFIED SOLUTION
Avatar of xabi
xabi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kllewelyn

ASKER

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