PDA

View Full Version : Sends email twice


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>

MacSP
11-06-2002, 07:29 PM
I just looked at this quickly but it looks to me that it happens because in your list function you have the line document.ask.submit() just before you return true. I could be wrong but I believe that submitting the form in this manner avoids the onSubmit method, which is the only reason you aren't in an eternal loop. Remove that line and you should be okay.

odd_a_tee
11-06-2002, 07:41 PM
I removed the
return true
line and it still wants to send it twice. Argh!!!!
-O

MacSP
11-06-2002, 08:24 PM
sorry if I wasn't clear, I meant to remove the document.ask.submit() line. Tell me if that doesn't work.

odd_a_tee
11-06-2002, 08:38 PM
yes it just dawned on me that I was being redundant with using the onSubmit and the documet.submit scripts at the same time.
Thank you so much for your help. I was really stumped there for a second.
-O

glenngv
11-07-2002, 03:19 AM
actually you have 3 submits :D


function list(which){
...
document.ask.submit()
...

<form NAME="ask" METHOD=POST Action="" onSubmit="return list(this)"
...
<INPUT TYPE="submit" Value="EMAIL" onClick="list()" >

odd_a_tee
11-07-2002, 05:14 PM
I removed the document.ask.submit () line. and it seems to work fine.
The other two (submits) seem to be interdependent. If there is a way to accomplish the same thing but using say a regular button. I would be interested to know it. I have tried
<INPUT TYPE="button" Value="EMAIL" onClick="list()">
but it doesn't seem to go.
-O

glenngv
11-11-2002, 03:19 AM
if you use a regular button, then you have to put back again the document.ask.submit() line and you have to remove the onsubmit event handler.