Javascript/VBscript hidden values & page redirect

Status
Not open for further replies.

Sridhar_Rao

In the zone
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

हॉर्न ओके प्लीज़
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>
 

victor_rambo

हॉर्न ओके प्लीज़
^That will be dynamically decided, when the user makes a selection from the drop down.
Isn't that how you wanted it?
 
OP
Sridhar_Rao

Sridhar_Rao

In the zone
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

हॉर्न ओके प्लीज़
^That is because you have not declared the ID attribute in that element. Do it and it shall work.
 
OP
Sridhar_Rao

Sridhar_Rao

In the zone
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.
 
Last edited:
OP
Sridhar_Rao

Sridhar_Rao

In the zone
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;
}
 
Last edited:

victor_rambo

हॉर्न ओके प्लीज़
^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;
 
OP
Sridhar_Rao

Sridhar_Rao

In the zone
<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.
 
OP
Sridhar_Rao

Sridhar_Rao

In the zone
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
 
Last edited:

victor_rambo

हॉर्न ओके प्लीज़
Oh, I forgot to tell you, I am posting in javascript, make sure to use its equivalent in VBscript, else it obviously wont work!
 
OP
Sridhar_Rao

Sridhar_Rao

In the zone
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
 
Status
Not open for further replies.
Top Bottom