Solved

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

Posted on 2003-11-06
6
307 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
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…
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 …
Suggested Courses

623 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