Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-11-06
6
Medium Priority
?
317 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 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
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

824 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