Solved

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

Posted on 2003-11-06
6
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xml xsd validation free tool to download 10 107
SEO friendly way to have two domains on website 9 96
website content maintenance 3 137
Where do I learn ES6? 3 84
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

751 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