Click to See Complete Forum and Search --> : Web form that can populate To box in new message window
khardy
10-01-2003, 07:41 AM
Hi
I am trying to build a page that displays the names of our schools with a checkbox next to each one. The value of each checkbox is the email address of the principal. When a user ticks a number of checkboxes and clicks Send, a new message window opens with the To: box populated with the selected addresses.
There's no problem in getting the form to send the email, however I really need for a new message window in the default email client to open.
If anyone can help me, very much appreciated!
You'd be better off using a server-side language to do this. What if the client doesn't have a default email program (or any program at all)?
khardy
10-01-2003, 07:47 AM
Sorry, I didn't mention that it was for use on our intranet so it is a known environment.
Try this, then (tested in IE6 with Outlook 2002). It will send it to the default address, as well as any addresses checked in the checkbox:
<script type="text/javascript">
function setAddresses() {
actionstr = "";
obj = document.forms[0].email;
for (i=0; i<obj.length; i++) {
if (obj[i].checked) {
actionstr += "; "+obj[i].value;
}
}
document.forms[0].action += actionstr;
document.forms[0].submit();
}
</script>
</head>
<body>
<form action="mailto:default@your.com" enctype="text/plain" method="post" onsubmit="setAddresses(); return false;">
One <input type="checkbox" name="email" value="first@your.com">
Two <input type="checkbox" name="email" value="second@your.com">
Three <input type="checkbox" name="email" value="third@your.com">
<input type="text" name="test">
<input type="submit" value="Submit">
</form>
khardy
10-01-2003, 08:31 AM
Thanks for your help :)
I can't get it to work though! Do I need to name the checkbox fields or am I missing something else?
The checkboxs must be named "email" and the form must be the first one on the page (if it isn't, just change the index in the forms array. ie, forms[1] etc...
khardy
10-01-2003, 08:45 AM
Sorry, it was working - the emails are sitting in my outbox with the subject line 'Form posted from Microsoft Internet Explorer'.
Is there a way for the new message window to have the To: box populated as per the form without sending it. We need to be able to add to the email, etc before sending it?
Also, it adds the addresses again in the body of the message - can this be changed?
Thanks for your help again.
:)
khardy
10-01-2003, 05:34 PM
Hi again
I'm getting desperate! The script below works exactly how I want it to, except I need to be able to check more than one checkbox.
<form name="myForm"> <input type="checkbox" name="email" value="info@sgs.adl.catholic.edu.au">
St Gabriel's School<br>
<input type="checkbox" name="email" value="info@antonio.adl.catholic.edu.au">
Antonio Catholic School</form> <a href="" onclick="javascript:this.href='mailto:'+document.myForm.email.value;">Compose Email</a>
Any ideas on how can expand the script to get more than one recipients address in the to: box much appreciated. We'll all be jumping with joy for a week or two (at least)!
Ah, ok... I think I see what you need:
<script type="text/javascript">
function setAddresses() {
actionstr = "";
obj = document.forms[0].email;
for (i=0; i<obj.length; i++) {
if (obj[i].checked) {
actionstr += obj[i].value+";";
}
}
document.getElementById("addresses").href = "mailto:"+actionstr;
}
</script>
</head>
<body>
<form action="">
<p>One <input type="checkbox" name="email" value="first@your.com" onclick="setAddresses();">
Two <input type="checkbox" name="email" value="second@your.com" onclick="setAddresses();">
Three <input type="checkbox" name="email" value="third@your.com" onclick="setAddresses();"></p>
</form>
<p><a href="mailto:default@your.com" id="addresses">test</a></p>and default@your.com is the default email address, to keep you page accessable for those without JavaScript...
khardy
10-01-2003, 10:32 PM
This works a treat! :)
Thank you soooooo much for your help!
You are welcome. I was happy to help... :)
khardy
10-14-2003, 03:14 AM
Hi
We were really, really ecstatic with our page to select email addresses from - however, for some reason it will not let us select more than 39 names.
Our page consists of 107 schools, and it works perfectly if you select from 1 to 39 names. However if you select 40, it either fails to open the message window or comes back with an error that the email client is not set up. I can't see anything in the javascript that would limit it to a certain number.
Any ideas?
Your help with this is very much appreciated. I know it is easy to see that this is not my forte.:confused:
I've never tried it with even close to that number, so I don't know why it maxed out. I personally would just user a server-side language (such as PHP, CGI/Perl, etc) to do this...