Javascript Checkform Not Working.....:(
Posted: Thu Mar 13, 2003 5:54 pm
I'm making a form and when I hit submit it will submit the form even if I leave everything blank...............what am i doing wrong??
here's the code:
<html>
<head>
<script language="JavaScript">
<!-- Hide from older browsers...
//Function to check form is filled in correctly before submitting
function CheckForm () {
var errorMsg = "";
//Check for a Subject
if (document.frmPMs.pmSubject.value==""){
errorMsg += "
You must enter a subject.";
}
//Check for a Message Body
if (document.frmPMs.pmBody.value==""){
errorMsg += "
You must enter a message body.";
}
//If there is aproblem with the form then display an error
if (errorMsg != ""){
msg = "_______________________________________________________________
";
msg += "The form has not been submitted because there are problem(s) with the form.
";
msg += "Please correct the problem(s) and re-submit the form.
";
msg += "_______________________________________________________________
";
msg += "The following field(s) need to be corrected: -
";
errorMsg += alert(msg + errorMsg + "
");
return false;
}
return true;
}
// -->
</script>
</head>
<title>PM Groups Mod by Fernan</title>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="50%" id="AutoNumber1" height="95" align = "center">
<tr>
<td width="100%" height="95" valign="top">
<form method="post" name="frmPMs" action="send_pms.asp" onSubmit="return CheckForm()">
<center>PM Group Mod by Fernan</center>
<p style="margin-left: 10; margin-right: 10">
Group to PM:
<select size="1" name="pmGID">
<option value="1">Forum Ådministrator</option>"
<option value="3">Forum Moderator</option>"
<option value="4">Newbie</option>"
<option value="5">Full Member</option>"
<option value="6">Advanced Member</option>"
<option value="7">Underground Member</option>"
</select>
Subject: <input type="text" name="pmSubject" size="30" maxlength="41">
<textarea rows="13" name="pmbody" cols="54"></textarea>
<center><input type="Submit" value="Send" name="Submit"> <input type="reset" value="Reset" name="Reset"></center>
</form>
</p>
</td>
</tr>
</table>
<div align="center">
</div>
</html>
Archived topic from Iceteks, old topic ID:359, old post ID:1769
here's the code:
<html>
<head>
<script language="JavaScript">
<!-- Hide from older browsers...
//Function to check form is filled in correctly before submitting
function CheckForm () {
var errorMsg = "";
//Check for a Subject
if (document.frmPMs.pmSubject.value==""){
errorMsg += "
You must enter a subject.";
}
//Check for a Message Body
if (document.frmPMs.pmBody.value==""){
errorMsg += "
You must enter a message body.";
}
//If there is aproblem with the form then display an error
if (errorMsg != ""){
msg = "_______________________________________________________________
";
msg += "The form has not been submitted because there are problem(s) with the form.
";
msg += "Please correct the problem(s) and re-submit the form.
";
msg += "_______________________________________________________________
";
msg += "The following field(s) need to be corrected: -
";
errorMsg += alert(msg + errorMsg + "
");
return false;
}
return true;
}
// -->
</script>
</head>
<title>PM Groups Mod by Fernan</title>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="50%" id="AutoNumber1" height="95" align = "center">
<tr>
<td width="100%" height="95" valign="top">
<form method="post" name="frmPMs" action="send_pms.asp" onSubmit="return CheckForm()">
<center>PM Group Mod by Fernan</center>
<p style="margin-left: 10; margin-right: 10">
Group to PM:
<select size="1" name="pmGID">
<option value="1">Forum Ådministrator</option>"
<option value="3">Forum Moderator</option>"
<option value="4">Newbie</option>"
<option value="5">Full Member</option>"
<option value="6">Advanced Member</option>"
<option value="7">Underground Member</option>"
</select>
Subject: <input type="text" name="pmSubject" size="30" maxlength="41">
<textarea rows="13" name="pmbody" cols="54"></textarea>
<center><input type="Submit" value="Send" name="Submit"> <input type="reset" value="Reset" name="Reset"></center>
</form>
</p>
</td>
</tr>
</table>
<div align="center">
</div>
</html>
Archived topic from Iceteks, old topic ID:359, old post ID:1769