odd_a_tee
11-06-2002, 07:01 PM
I have an email form that could go to one of three people. This is determined by a set of radio buttons at the bottom of the form. I don't want people sending nothing (I am not too picky about validation as it is not going to a DB) so I borrowed a simple validation from someone on this site. The validation works and the radio buttons work to determine the ACTION when I test them seperately. However when I combine them the form wants to email twice. WHY???
I have included the code below.
Thanks, any help is greatly appreciated
Odd_a_tee
<html>
<head>
<title>Untitled Document</title>
<script language="JavaScript">
<!--
function list(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
pass=false
break
}
}
}
}if(pass == true){
page = document.ask.who
if (page[0].checked) {
document.ask.action = "mailto:aa@aa.com"
}else if (page[1].checked){
document.ask.action = "mailto:bb@bb.com"
}else if(page[2].checked){
document.ask.action = "mailto:cc@cc.com"
}
document.ask.submit()
return true
}
if (!pass){
alert("One or more of the required elements are not completed. Please complete them, then submit again!")
return false
}
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form NAME="ask" METHOD=POST Action="" onSubmit="return list(this)" ENCTYPE="TEXT/PLAIN">
<p>
Name: <input type="text" name="requiredname" size="32" maxlength="80"></p>
<span class="side"> (as you want it to appear in the response)</span><br>
<p>E-mail Address: <input type="text" name="requiredemail" size="32" maxlength="80"></p>
<p>Your Question: <br><textarea rows="5" name="requiredquestion" cols="40"></textarea>
</p>
<p>Who would you like a response from? <br>
Steven <input type=radio name="who" value= "aa" checked >
Nancy <input type=radio name="who" value= "bb" >
Either <input type=radio name="who" value= "cc" ></P>
<INPUT TYPE="submit" Value="EMAIL" onClick="list()" >
</form>
</body>
</html>
I have included the code below.
Thanks, any help is greatly appreciated
Odd_a_tee
<html>
<head>
<title>Untitled Document</title>
<script language="JavaScript">
<!--
function list(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
pass=false
break
}
}
}
}if(pass == true){
page = document.ask.who
if (page[0].checked) {
document.ask.action = "mailto:aa@aa.com"
}else if (page[1].checked){
document.ask.action = "mailto:bb@bb.com"
}else if(page[2].checked){
document.ask.action = "mailto:cc@cc.com"
}
document.ask.submit()
return true
}
if (!pass){
alert("One or more of the required elements are not completed. Please complete them, then submit again!")
return false
}
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form NAME="ask" METHOD=POST Action="" onSubmit="return list(this)" ENCTYPE="TEXT/PLAIN">
<p>
Name: <input type="text" name="requiredname" size="32" maxlength="80"></p>
<span class="side"> (as you want it to appear in the response)</span><br>
<p>E-mail Address: <input type="text" name="requiredemail" size="32" maxlength="80"></p>
<p>Your Question: <br><textarea rows="5" name="requiredquestion" cols="40"></textarea>
</p>
<p>Who would you like a response from? <br>
Steven <input type=radio name="who" value= "aa" checked >
Nancy <input type=radio name="who" value= "bb" >
Either <input type=radio name="who" value= "cc" ></P>
<INPUT TYPE="submit" Value="EMAIL" onClick="list()" >
</form>
</body>
</html>