Solved

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

Posted on 2004-08-16
10
292 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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
Oh silly me, I read it wrong.  You're testing for value, and I'm testing for selectedIndex !
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Author Comment

by:Caiapfas
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
could you guys take a look at this one..also
http://www.experts-exchange.com/Programming/Q_21092129.html
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

772 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

10 Experts available now in Live!

Get 1:1 Help Now