Solved

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

Posted on 2003-11-06
6
262 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now