DIGIT-ARC read-only archive · snapshot: July 23, 2026

Javascript/VBscript hidden values & page redirect

15 posts · originally from https://geek.digit.in/community/threads/javascript-vbscript-hidden-values-page-redirect.102830/

Sridhar_Rao
Sridhar_Rao Original post #1
Nov 24, 2008 at 8:23 PM
I have a html form, where user makes a choice using drop-down menu. There are other elements in the form too. I use a vbscript to send the element values to my email.
Code:
<form name="test" method="post" action="cdosys.asp">
<input name="_recipients" type="hidden" value="mymail@myurl.com" />
<input name="_requiredFields" type="hidden"  value="name,email,country" />
<input name="_replyToField" type="hidden" value="email" />
<input name="_redirect" type="hidden" [COLOR=Red]value=""[/COLOR] />
This works when a predetermined value is entered. for eg. value="this.htm"
How do I place the value of input name (in red colour), depending on what the user chooses? What is the code?
victor_rambo
Nov 24, 2008 at 8:52 PM
Code:
<select id="ddbox" onchange="document.getElementById('redirect').value=this.value">
   <option value="location1.html">Location 1</option>
   <option value="location2.html">Location 2</option>
   <option value="location3.html">Location 3</option>
</select>
Sridhar_Rao
Nov 24, 2008 at 9:01 PM
Thanks, but what should go into the value=""?
Code:
<input name="_redirect" type="hidden" value="" />
victor_rambo
Nov 24, 2008 at 9:05 PM
^That will be dynamically decided, when the user makes a selection from the drop down.
Isn't that how you wanted it?
Sridhar_Rao
Nov 24, 2008 at 9:11 PM
Yes, but you did not get my point. The code
Code:
onchange="document.getElementById('redirect').value=this.value"
places the value into the hidden element redirect.
But, the question is what should I mention in this line?
Code:
<input name="_redirect" type="hidden" [COLOR=Red]value="" [/COLOR]/>

The code is not working, as the value is not specified here (value="")
victor_rambo
Nov 24, 2008 at 9:16 PM
^That is because you have not declared the ID attribute in that element. Do it and it shall work.
Sridhar_Rao
Nov 24, 2008 at 9:23 PM
I tried that too. Here is the code
Code:
<select size="1" name="choice" id="choice" onchange="document.getElementById('redirect').value=this.value">
what about this one? Should it be
Code:
<input name="_redirect" type="hidden"  />
or
<input name="_redirect" type="hidden"  value=""/>
Anyway, it does not work.

I tried another workaround.
Code:
<select size="1" name="choice" id="choice" onchange="goto()">
function goto(){
x1 = document.test.choice.selectedIndex; 
x2 = document.test.choice.options[x1].value;
document.getElementById('_redirect').value=x3;
}
This doesn't work too.

I guess, I am making a mistake here. You are probably referring to hidden element's id. I now corrected it to
Code:
<input name="_redirect" type="hidden" id="hid" />
and made correction here:
Code:
<select size="1" name="choice" id="choice" onchange="document.getElementById('hid').value=this.value">
yet, it doesn't work.
victor_rambo
Nov 24, 2008 at 9:34 PM
^how are you confirming if it works or not?
Sridhar_Rao
Nov 24, 2008 at 9:35 PM
The page is not getting redirected at all. Anything wrong with the code?
Code:
<input name="_redirect" type="hidden" id="hid" value="" />
<select size="1" name="choice" id="choice" onchange="goto()">
function goto(){
x1 = document.test.choice.selectedIndex; 
x2 = document.test.choice.options[x1].value;
document.getElementById('hid').value=x3;
}
victor_rambo
Nov 24, 2008 at 9:46 PM
^Thats because nowhere you have used the code for redirection. You just said that you want the redirection value to be put in the hidden field.
Code:
window.location=document.getElementById('redirect').value;
Sridhar_Rao
Nov 24, 2008 at 9:51 PM
<input name="_redirect" type="hidden" id="hid" value="" />

The VBScript handles this. I am sending all the parameters to cdosys.asp, which does all the redirection business. My interest is to get a value to this element.

If I enter anything for this value="abcd.htm", it works fine. I only have to give that value dynamically based on user selection.
B
Bandu #12
Nov 24, 2008 at 10:10 PM
^Your id="hid" should be id="redirect" for Rohans code to work.
Sridhar_Rao
Nov 24, 2008 at 10:15 PM
That is not an issue, I have referred the same id in both places. I have used hid in the element as well as in the script.

Well, I got it working now. I had made a simple, but stupid mistake. I was passing the value by value and then trying to catch it by reference.
*www.microrao.com/ident1.htm
victor_rambo
Nov 24, 2008 at 10:21 PM
Oh, I forgot to tell you, I am posting in javascript, make sure to use its equivalent in VBscript, else it obviously wont work!
Sridhar_Rao
Nov 24, 2008 at 10:28 PM
No, your post was the right one. I messed it up due to my stupidity. Read above and you will know. All I had to in the javascript function was to add this line:
Code:
document.getElementById('hid').value=document.test.choice.value;
And it works. Thanks Rohan