Solved

Changing Form Submit E-mail Address based on Drop Down Selection

Posted on 2010-11-17
6
400 Views
Last Modified: 2012-08-14
I'm attempting to set-up a form to submit to a different e-mail address depending on the selection from the drop down menu.

The drop down code looks like this:

<select class="drop-field" name="Directed" id="Directed">
<option></option>
<option value="example@example.com">Guest Room & Suite information </option>
<option value="example@example.com">About Your Stay </option>
<option value="example@example.com">Group Sales & Catering</option>
<option value="example@example.com">Job Inquiries & Careers </option>
<option value="example@example.com">Lost & Found </option>
<option value="example@example.com">Other</option>
 </select>

Open in new window


The javascript looks like this:

<script type="text/javascript">								 
form.hdwemail.value = document.getElementById("Directed").options[document.getElementById("Directed").selectedIndex].value;
</script>

Open in new window


And the submit code looks like this:

<input type="hidden" name="hdwuploadfolder" id="hdwuploadfolder" value="uploads" />
<input type="hidden" name="hdwemail" id="hdwemail" value="" />
<input type="hidden" name="hdwok" id="hdwok" value="http://www.mayfieldinnedmonton.com/contact-ok.aspx" />
<input type="hidden" name="hdwnook" id="hdwnook" value="http://www.mayfieldinnedmonton.com/contact-error.aspx" />

Open in new window


In the end I'm trying to get the value of hdwemail to change to a different e-mail address depending on the drop down selection.

Any help would be appreciated.

Thank you
0
Comment
Question by:SysAdmin1030
[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
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:jmatix
ID: 34159232
Add an onchange event handler to select as:

<select class="drop-field" name="Directed" id="Directed" onchange="selChanged(this)">
<option></option>
<option value="example@example.com">Guest Room & Suite information </option>
<option value="example@example.com">About Your Stay </option>
<option value="example@example.com">Group Sales & Catering</option>
<option value="example@example.com">Job Inquiries & Careers </option>
<option value="example@example.com">Lost & Found </option>
<option value="example@example.com">Other</option>
 </select>

Then define JS function selChanged() as below:

<script>
function selChanged(sel)
{
 sel.frm.hdwemail.value = sel.options[sel.selectedIndex].value;
}
</script>

Open in new window

0
 

Author Comment

by:SysAdmin1030
ID: 34160268
That didn't seem to work...any ideas?
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34160607
Sorry there was a typo - frm instead of form. Correct as below:
<script>
function selChanged(sel)
{
 sel.form.hdwemail.value = sel.options[sel.selectedIndex].value;
}
</script>

Open in new window

0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:SysAdmin1030
ID: 34165864
It is obviously an issue with my code or the placement of my <script> because your  handler makes perfect sense.

I have placed the entire form code below let me know if you see anything that could be causing the issue; I appreciate all your help!

<form action="http://www.example.com/HDWASPForm2Excel/Form2Excel.asp" method="post" accept-charset="iso-8859-1">
<table id="contact-table" width="100%" border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                   <td class="form-title">*Name:</td>
                                   <td><input class="text-field" name="Name" type="text" maxlength="50" /></td>
                                  </tr>
                                  <tr>
                                   <td class="form-title">*Email:</td>
                                   <td><input class="text-field" name="Email" type="text" maxlength="50" /></td>
                                  </tr>
                                  <tr>
                                   <td class="form-title">Phone:</td>
                                   <td><input class="text-field" name="Phone" type="text" maxlength="50" /></td>
                                  </tr>
                                  <tr>
                                    <td class="form-title">Directed To:</td>
                                    <td><select class="drop-field" name="Directed" id="Directed" onchange="selChanged(sel)">
                                    <option></option>
                                    <option value="example@example.com">Guest Room & Suite information </option>
                                    <option value="example@example.com">About Your Stay </option>
                                    <option value="example@example.com">Group Sales & Catering</option>
                                    <option value="example@example.com">Job Inquiries & Careers </option>
                                    <option value="example@example.com">Lost & Found </option>
                                    <option value="example@example.com">Other</option>
                                    </select></td>
                                  </tr>
                                  <tr>
                                   <td class="form-title top">Comments:</td>
                                   <td><textarea name="Comments" class="box-field" cols="" rows=""></textarea></td>
                                  </tr>
                                  <tr>
                                   <td class="form-title top">&nbsp;</td>
                                   <td><button id="btn-send" type="submit"></button></td>
                                  </tr>
                                  <tr>
                                   <td class="form-title top">&nbsp;</td>
                                   <td><span class="small-quote">*required fields</span></td>
                                  </tr>
                                 </table>
                                 
                                 <script>
				 function selChanged(sel)
				 {
				 sel.form.hdwemail.value = sel.options[sel.selectedIndex].value;
				 }
				 </script>
                                 
                                 <input type="hidden" name="hdwuploadfolder" id="hdwuploadfolder" value="uploads" />
                                 <input type="hidden" name="hdwemail" id="hdwemail" value="" />
                                 <input type="hidden" name="hdwok" id="hdwok" value="http://www.example.com/contact-ok.aspx" />
                                 <input type="hidden" name="hdwnook" id="hdwnook" value="http://www.example.com/contact-error.aspx" />
                                </form>

Open in new window

0
 

Author Comment

by:SysAdmin1030
ID: 34175569
Oh and I caught the typo previously and that wasn't the cause of my issue.
0
 
LVL 16

Accepted Solution

by:
jmatix earned 500 total points
ID: 34188867
Change the line:

<select class="drop-field" name="Directed" id="Directed" onchange="selChanged(sel)">

To:

<select class="drop-field" name="Directed" id="Directed" onchange="selChanged(this)">

0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 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