Solved

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

Posted on 2004-08-16
10
293 Views
Last Modified: 2012-06-27
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
Comment
Question by:Caiapfas
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 15

Expert Comment

by:Colosseo
ID: 11815860
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
 
LVL 18

Expert Comment

by:arantius
ID: 11815886

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
 
LVL 18

Expert Comment

by:arantius
ID: 11815896
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
 
LVL 15

Expert Comment

by:Colosseo
ID: 11815916
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
 
LVL 18

Expert Comment

by:arantius
ID: 11815928
Oh silly me, I read it wrong.  You're testing for value, and I'm testing for selectedIndex !
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 2

Author Comment

by:Caiapfas
ID: 11822215
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
 
LVL 18

Expert Comment

by:arantius
ID: 11822901
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
 
LVL 15

Accepted Solution

by:
Colosseo earned 500 total points
ID: 11822916
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
 
LVL 10

Expert Comment

by:avidya
ID: 11823030
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
 
LVL 2

Author Comment

by:Caiapfas
ID: 11823232
could you guys take a look at this one..also
http://www.experts-exchange.com/Programming/Q_21092129.html
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API Soap Calls 4 86
GPS save in database 19 58
reposition hamburger icon to top of screen 5 60
Do you know any Office editor web for IIS or Apache web server)??? 10 78
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This video teaches users how to migrate an existing Wordpress website to a new domain.

932 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now