• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

I need this to change the reciptant depending on option selected...500points

I have an form that I'm trying to change the reciptant depending on the option selected from the drop down box "What is the regrauding?"
Form location : http://www.ticketstogo.com/contactus.htm

It will need to change the option in this hidden feild...
but i want it to send email to a certian email adresses all the time and change the other depeneding on the option selected.

        <input type=hidden name="recipient" value="alwayssendhere@test.com,changes@test.com">


Thanks,
Caiapfas
0
Caiapfas
Asked:
Caiapfas
  • 4
  • 3
  • 2
  • +1
1 Solution
 
ColosseoCommented:
Hi Caiapfas

You will be able to accomplish this with a simple piece of javascript. I have created an example html file as this seemed the best way to explain it

The main points to note are

1. onChange event of the select which calls the javascript
2. value of the options relating to the case statement in the javascript

<html>
<head>
</head>
<script language="JavaScript" type="text/JavaScript">

  function get_Email() {
    // use the value of the selected option to  choose the correct email address
      switch (document.getElementById("lstOption").value) {
      case "1":
              var str_Email = "option1@test.com";
              break;
        case "2":
              var str_Email = "option2@test.com";
              break;
        case "3":
              var str_Email = "option3@test.com";
              break;
      }  
 
  // Output the always email address along with the one specific to the selected option
  document.getElementById("recipient").value = "alwayssendhere@test.com," + str_Email;
  }

</script>
<body>
<form action="" method="post" name="frmMain">
<input type=hidden name="recipient" value="alwayssendhere@test.com,option1@test.com">
<select name="lstOption" onChange="get_Email()">
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
</select>
</form>
</body>
</html>

HTH and if you require more explanation please ask :)

Regards

Scott
0
 
arantiusCommented:

And so on where the number after case is the index of the <option>.


<script type="text/javascript">
function setRecip(sel) {
  var r=document.getElementById("recipient");
  switch (sel.selectedIndex) {
  case 0:
    r.value="abc";
    break;
  case 1:
    r.value="def";
    case;
  }
}
</script>


<select name="regarding" onchange="setRecip(this)">
....
</select>
<input type="hidden" name="recipient" id="recipient" />
0
 
arantiusCommented:
You must have gotten a bit of a head start C ;-)
But I'm 99.9% sure that the case you need to test for will start at 0, not 1.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ColosseoCommented:
Hi arantius

- But I'm 99.9% sure that the case you need to test for will start at 0, not 1.

Actually not in my example as the only possible values for the select are 1,2 or 3 so there is no need to test for a case of 0 :)

Regards

Scott
0
 
arantiusCommented:
Oh silly me, I read it wrong.  You're testing for value, and I'm testing for selectedIndex !
0
 
CaiapfasAuthor Commented:
ok this isnt working at all..
shouldnt it change the second email automaticlly so when i do a veiw source it shows the change?
its not working





--------------------------------------------------------------


<script language="JavaScript" type="text/JavaScript">

  function get_Email() {
    // use the value of the selected option to  choose the correct email address
     switch (document.getElementById("lstOption").value) {
      case "0":
            var str_Email = "bill@test.com";
            break;
       case "1":
            var str_Email = "kim@test.com";
            break;
       case "2":
            var str_Email = "sales@test.com";
            break;
       case "3":
            var str_Email = "gina@test.com";
            break;            
       case "4":
            var str_Email = "marcus@test.com";
            break;  
       case "5":
            var str_Email = "kimbo@test.com";
            break;                      
       case "6":
            var str_Email = "support@test.com";
            break;            
     }  
     
 
  // Output the always email address along with the one specific to the selected option
  document.getElementById("recipient").value = "alwayssendhere@test.com," + str_Email;
  }

</script>

<form action="" method="post" name="frmMain">
<input type=hidden name="recipient" value="support@test.com, str_Email">
<select name="lstOption" onChange="get_Email()">
<option value="0">option 1</option>
<option value="1">option 2</option>
<option value="2">option 3</option>
<option value="3">option 3</option>
<option value="4">option 3</option>
<option value="5">option 3</option>
<option value="6">option 3</option>
</select>
</form>
0
 
arantiusCommented:
No.  Changing values with javascript will not change the original source file.  It will change the values submitted to the server when you hit the form submit button.
0
 
ColosseoCommented:
Hi Caiapfas

Because the value of recipient is being set by the javascript you wont be able to see it changing by using view source.

the variable str_Email can only be referenced inside the javascript so your line

<input type=hidden name="recipient" value="support@test.com, str_Email"> won't work

I have changed the code to include some additions, namely;

onload = function() { get_Email('0'); } <-- set the email address to the first option when the page loads
alert(document.getElementById("recipient").value); <-- this line will show you the email address changing as you select options (can be removed once you are happy)

when you view the source the value will always be "" but the alert will show you the value changing

<html>
<head></head>
<script language="JavaScript" type="text/JavaScript">

  function get_Email() {
    // use the value of the selected option to  choose the correct email address
     switch (document.getElementById("lstOption").value) {
      case "0":
            var str_Email = "bill@test.com";
            break;
       case "1":
            var str_Email = "kim@test.com";
            break;
       case "2":
            var str_Email = "sales@test.com";
            break;
       case "3":
            var str_Email = "gina@test.com";
            break;            
       case "4":
            var str_Email = "marcus@test.com";
            break;  
       case "5":
            var str_Email = "kimbo@test.com";
            break;                      
       case "6":
            var str_Email = "support@test.com";
            break;            
     }  
     
 
  // Output the always email address along with the one specific to the selected option
  document.getElementById("recipient").value = "alwayssendhere@test.com," + str_Email;
 
  //out put the value of the email to show it changing (this can be deleted once happy)
  alert(document.getElementById("recipient").value);
  }

  // Run when the page loads and set the value of the email address to the first option
  onload = function() { get_Email('0'); }


</script>
<body>
<form action="" method="post" name="frmMain">
<input type=hidden name="recipient" value="">
<select name="lstOption" onChange="get_Email()">
<option value="0">option 1</option>
<option value="1">option 2</option>
<option value="2">option 4</option>
<option value="3">option 5</option>
<option value="4">option 6</option>
<option value="5">option 7</option>
<option value="6">option 8</option>
</select>
</form>

</body>
</html>

Regards

Scott
0
 
avidyaCommented:
Hi,
try this code below.
If have altered the values of the listbox to mailaddresses and made an onchange event.
The alert is showing you what is does.

=============
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<form>
 <table cellpadding="0" cellspacing="0" border="1" width="550" style="border-collapse: collapse" bordercolor="#111111">
 <tr>
  <td align="right"><p><b><font size="2" face="Arial">What is your inquiry regarding?</font></b></p></td>
  <td>
   <select onchange="document.all.recipient.value='alwayssendhere@test.com,'+contact_area.value;alert(document.all.recipient.value);" name="contact_area" style="font-family: verdana,arial,helvetica; width: 330px; background-color: #cccccc; color: #000000; font-size: 12px; border:1px #968E86 dashed; padding:1px;" size="1">
    <option></option>
    <option value="workquote@test.com">Work Quote</option>
    <option value="help_question@test.com">Help/Question</option>
    <option value="general@test.com">General inquiries?</option>
    <option value="tech_support@test.com">Tech Support</option>
    <option value="inquire@test.com">Inquiries about the website?</option>
    <option value="none_above@test.com">None of the above</option>
   </select>
  </td>
 </tr>
 <tr>
  <td align="right"><p><font size="2" face="Arial">&nbsp;</font></b></p></td>
  <td><input type="submit" value="send" id=submit1 name=submit1>
 </tr>
 </table>
 <input type=hidden name="recipient" value="">

</form>

</BODY>
</HTML>
0
 
CaiapfasAuthor Commented:
could you guys take a look at this one..also
http://www.experts-exchange.com/Programming/Q_21092129.html
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now