PDA

View Full Version : Posting an HTML form to specified emails addresses depending on a selection


jamesthecat
03-17-2003, 02:24 PM
I'm building a web page which has a contact form. The client requires the form to be emailed to a particular person depending on the nature of the query which the user will select from a drop down menu.
Can someone point me in the right direction please? A colleague mentioned something about switches...

Many thanks.

JTC

Spudhead
03-17-2003, 04:08 PM
function pingEmailsAllOverThePlace(){
var querySubject=document.myForm1.mySelectBox[document.myForm1.mySelectBox.selectedIndex].value

switch (querySubject){
case 'sales':
document.myForm2.action="mailto:someone@somewhere.com";
break;
case 'support':
document.myForm2.action="mailto:someone.else@somewhere.com";
break;
default:
document.myForm2.action="mailto:webmaster@somewhere.com";
break;
}
}


=======================================

Note that this method requires that the subject is in its own form. You could redo it pretty easy to run all in the same form.

jamesthecat
03-17-2003, 04:12 PM
Thanks for this I'll give it a try.

JTC
:)

jamesthecat
03-18-2003, 10:53 AM
Hi SpudHead

Thanks for your code. It certainly pointed me in the right direction.
My colleague varied it slightly and came up with this:

function set_recipient() {
var querySubject=document.email.advice[document.email.advice.selectedIndex].value;
document.email.subject.text = querySubject;
window.alert(document.email.recipient.value);
switch(querySubject){
case "clmmc" : document.email.recipient.value = "someone@somwhere.com" ; break;
case "gw" : document.email.recipient.value = "someone2@somwhere.com" ; break;
case "mm" : document.email.recipient.value = "someone@somwhere.com3" ; break;
case "fmew" : document.email.recipient.value = "someone4@somwhere.com" ; break;
default: document.email.recipient.value = "someone@somwhere.com"; break;
}

JTC

Spudhead
03-18-2003, 03:03 PM
Cool - although I preferred my function name ;)