?
Solved

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

Posted on 2004-08-16
10
Medium Priority
?
303 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
[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
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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
 
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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
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:
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

743 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