# Javascript/VBscript hidden values & page redirect



## Sridhar_Rao (Nov 24, 2008)

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.

```
<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)

```
<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)

Thanks, but what should go into the value=""?

```
<input name="_redirect" type="hidden" value="" />
```


----------



## victor_rambo (Nov 24, 2008)

^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)

Yes, but you did not get my point. The 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?

```
<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)

^That is because you have not declared the ID attribute in that element. Do it and it shall work.


----------



## Sridhar_Rao (Nov 24, 2008)

I tried that too. Here is the code

```
<select size="1" name="choice" id="choice" onchange="document.getElementById('redirect').value=this.value">
```
what about this one? Should it be 

```
<input name="_redirect" type="hidden"  />
or
<input name="_redirect" type="hidden"  value=""/>
```
Anyway, it does not work.

I tried another workaround.

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

```
<input name="_redirect" type="hidden" id="hid" />
```
and made correction here:

```
<select size="1" name="choice" id="choice" onchange="document.getElementById('hid').value=this.value">
```
yet, it doesn't work.


----------



## victor_rambo (Nov 24, 2008)

^how are you confirming if it works or not?


----------



## Sridhar_Rao (Nov 24, 2008)

The page is not getting redirected at all. Anything wrong with the 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)

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

```
window.location=document.getElementById('redirect').value;
```


----------



## Sridhar_Rao (Nov 24, 2008)

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


----------



## Bandu (Nov 24, 2008)

^Your *id="hid"* should be *id="redirect"* for Rohans code to work.


----------



## Sridhar_Rao (Nov 24, 2008)

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)

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)

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:

```
document.getElementById('hid').value=document.test.choice.value;
```
And it works.  Thanks Rohan


----------

