PDA

View Full Version : Please help! Sending radio button value to multiple emails


jssuche
03-25-2010, 06:53 AM
I have three radio button groups with different values. My script only works for one group. Please help!


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function emailTo(){

var emails = document.getElementsByName("email1");
var emailAdress = null;

for(var i = 0; i < emails.length; i++){
if(emails[i].checked){
emailAdress = emails[i].value;
}
}

if(emailAdress == null){
alert("select the email address");
return;
}

var mailto_link = 'mailto:'+emailAdress;

var win = window.open(mailto_link,'emailWindow');
if (win && win.open &&!win.closed) win.close();

}
</script>

</head>
<body>

<p>
<input type = "radio" name = "email1" value = "email1.com"/>
recipient 1a
<input type = "radio" name = "email1" value = "email1.com">
recipient 1b
</p>
<p>
<input type = "radio" name = "email2" value = "email2.com"/>
recipient 2a
<input type = "radio" name = "email2" value = "email2.com">
recipient 2b</p>
<p>
<input type = "radio" name = "email3" value = "email3.com"/>
recipient 3a
<input type = "radio" name = "email3" value = "email3.com">
recipient 3b</p>
<p>&nbsp;</p>
<p>
<input type = "button" onClick = "emailTo()" value = "Email"/>
</p>
</body>
</html>

DJCMBear
03-25-2010, 07:00 AM
from your script it only works for one because you havent called the other two.

jssuche
03-25-2010, 07:05 AM
from your script it only works for one because you havent called the other two.


I am pretty new in this. Could you please sugest the code I can use ?

DJCMBear
03-25-2010, 07:13 AM
what I would do is put each code into an array so something like:

var emails =new Array();
emails[0] = document.getElementByName("email1");
emails[1] = document.getElementByName("email2");
emails[2] = document.getElementByName("email3");


then do the for loop.

jssuche
03-25-2010, 07:24 AM
what I would do is put each code into an array so something like:

var emails =new Array();
emails[0] = document.getElementByName("email1");
emails[1] = document.getElementByName("email2");
emails[2] = document.getElementByName("email3");


then do the for loop.

if I replace var emails = document.getElementsByName("email1"); with your code I get an error. Could you please put your code into mine provided above?

Philip M
03-25-2010, 09:09 AM
jssuche and DJCMBear -

Please read and take note of http://www.codingforums.com/showthread.php?t=17515.

bardonw
03-26-2010, 04:40 PM
I tested the following code in Firefox and Internet Explorer. I believe that it will do the trick:

for(var emails = [], i = 1; i <= 3; i++)
for(var elems = document.getElementsByName("email" + i), j = 0; j < elems.length; j++)
emails.push(elems[j]);