[thelist] please help - Javascript variables
Brian Delaney
brian.delaney at mccmh.net
Wed Dec 22 07:59:45 CST 2004
I am now noticing a problem when writing it as a hidden field.
When the user clicks the login button it runs a javascript function
that sets a value asp checks to see if form has been posted then submits
the form.
My asp pulls the variable as follows: request("myVar") amongst the
username and password variables.
I get an error saying variable myvar is not defined.
any ideas?
Matt Warden wrote:
>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,
>
>
>
>
*
*
*
This message, including any attachments, is intended solely for the use of the named recipient(s) and may contain confidential and/or priveleged information. Any unauthorized review, use, disclosure or distribution of this communication(s) is expressly prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy any and all copies of the original message.
More information about the thelist
mailing list