Solved

can you dynamically add a hidden input based on a drop down selection?

Posted on 2003-11-06
6
288 Views
Last Modified: 2010-04-06
i have a form that is processed through an asp formMail script.  in the form, a drop down list determines who will recieve the email.  but from this selection, i also want to pass another input, preferrably hidden.

<select name=drop1>
<option value="email1@here.com">Person1
<option value="email2@here.com">Person2
<option value="email3@here.com">Person3
</select>

if Person2 is selected, the form will be sent to email2@here.com.  i also want to pass a hidden variable with the value of "Person2".  is this possible?  thanks.
0
Comment
Question by:studiojg
6 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 9698142
Try this ...

<script>
function Drop1OnChange(oThis)
{
      oThis.form.MyHiddenInput.value = oThis.options[oThis.selectedIndex].value;
}
</script>

<form>

<select name=drop1 onchange="Drop1OnChange(this)">
<option value="email1@here.com">Person1
<option value="email2@here.com">Person2
<option value="email3@here.com">Person3
</select>

<input type="hidden" name="MyHiddenInput">

</form>
0
 
LVL 58

Accepted Solution

by:
amit_g earned 125 total points
ID: 9698144
The line

oThis.form.MyHiddenInput.value = oThis.options[oThis.selectedIndex].value;

should rather be

oThis.form.MyHiddenInput.value = oThis.options[oThis.selectedIndex].text;
0
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9699965
The information in the selection-box is coming from someplace; ie: at some point you filled that select box with values.
Using that information you should be able to lookup the "name" when processing the form.

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 35

Expert Comment

by:YZlat
ID: 9710706
You can do that with asp:


<form name="form1" method="post" action="Nameofyour page.asp">
<select name="drop1" onChange="form1.submit()">
<option value="email1@here.com">Person1</option>
<option value="email2@here.com">Person2</option>
<option value="email3@here.com">Person3</option>
</select>
<%
if request("drop1")="email1@here.com" then
%>
<input type="hidden" name="hidden1" value="Person1">
<%
elseif request("drop1")="email2@here.com" then
%>
<input type="hidden" name="hidden1" value="Person2">
if request("drop1")="email3@here.com" then
%>
<input type="hidden" name="hidden1" value="Person3">
<%
end if%>
</form>

0
 
LVL 35

Expert Comment

by:YZlat
ID: 9714675
sorry, made a slight error. Here is updated code:
<HTML>
<HEAD>
</HEAD>
<BODY>
<form name="form1" method="post" action="Page1.asp">

<select name="drop1" onChange="form1.submit()">
<option value="email1@here.com">Person1</option>
<option value="email2@here.com">Person2</option>
<option value="email3@here.com">Person3</option>
</select>
<%
if request("drop1")="email1@here.com" then
%>
<input type="hidden" name="hidden1" value="Person1">
<%
elseif request("drop1")="email2@here.com" then
%>
<input type="hidden" name="hidden1" value="Person2">
<%
elseif request("drop1")="email3@here.com" then
%>
<input type="hidden" name="hidden1" value="Person3">
<%
end if
%>
</form>


</BODY>
</HTML>
0
 

Author Comment

by:studiojg
ID: 9740555
thanks guys.  i was hoping to use javascript, so i went with that one, but i appreciate all the suggestions.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to dynamically set the form action using jQuery.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question