[thelist] please help - Javascript variables
Matt Warden
mwarden at gmail.com
Tue Dec 21 14:03:31 CST 2004
On Tue, 21 Dec 2004 14:24:38 -0500, Brian Delaney
<brian.delaney at mccmh.net> wrote:
> I am passing a window a javascript variable called myVar to a pop up window
>
> if I do something like alert(myVar) when the window loads it shows
> correctly.
>
> I need to use the variable in asp though. I have read that you can send
> it using a hidden input type in a form.
>
> I have tried this:
>
> <form name="frmLogin" ID="Form1">
> <input type="hidden" name="page" id="page" value="myVar">
> <etc. etc>
>
> When I retrieve it and try a response.write in asp I get this: myVar -
> so it's seeing the text only and not a variable.
>
> How do I pass the javascript variable myVar into the hidden Form? I have
> tried value=<%myVar%>, value="javascript(myVar)" none work.
You want to set the form field to the value of myVar, so you need to
do one of the following:
1. keep the form tag like you have it, and do something like this:
<script type="text/javascript">
window.onload = document.forms[0].elements['page'].value=myVar;
</script>
Note that you might have to do this:
window.onload = function() {document.forms[0].elements['page'].value=myVar;};
2. Write your input tag using javascript:
<script type="text/javascript">
document.writeln('<input type="hidden" name="page" value="'+ myVar +'">');
</script>
hth,
--
Matt Warden
Miami University
Oxford, OH
http://mattwarden.com
This email proudly and graciously contributes to entropy.
More information about the thelist
mailing list