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.
example
HREF=("/bin/file.cgi?instr
I tried that and the value seems to get lost.
Try this...........
<%
x="/bin/file.cgi?instr=" & instr
%>
<A href="<%=x%>">Lets Go</a>
Works for me, Give it a try........
;->
<%
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/fi le.cgi?ins tr="+instr ;
}
// -->
</script>
-Josh
<A HREF="JavaScript:void(0);"
<script language="javascript">
<!--
function goto()
{// any manipulation of variable instr here...
document.location="/bin/fi
}
// -->
</script>
-Josh
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
basically I'm doing this based on a click
top.or_main.location.href= ("/cgi-bin /or_image. cgi?instr= "+top.or_v ars.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.
top.or_main.location.href=
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.
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.
<a href="/bin/file.cgi?instr=
or this
<script language="javascript">
document.location="/bin/fi
</script>