Print Page | Close Window

Javascript CheckForm not working

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Web Design Discussion
Forum Description: Discussion on web design and development subjects.
URL: https://forums.webwiz.net/forum_posts.asp?TID=971
Printed Date: 28 March 2026 at 4:50pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Javascript CheckForm not working
Posted By: fernan82
Subject: Javascript CheckForm not working
Date Posted: 12 March 2003 at 7:17pm

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 += "\n\tYou must enter a subject.";
 }

 //Check for a Message Body
 if (document.frmPMs.pmBody.value==""){
  errorMsg += "\n\tYou must enter a message body.";
 }


 //If there is aproblem with the form then display an error
 if (errorMsg != ""){
  msg = "_______________________________________________________________\n\n";
  msg += "The form has not been submitted because there are problem(s) with the form.\n";
  msg += "Please correct the problem(s) and re-submit the form.\n";
  msg += "_______________________________________________________________\n\n";
  msg += "The following field(s) need to be corrected: -\n";

  errorMsg += alert(msg + errorMsg + "\n\n");
  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()">
<br>
<center><b>PM Group Mod by Fernan</b></center>
<br><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><br><br>
Subject: <input type="text" name="pmSubject" size="30" maxlength="41"><br>
<br>
<textarea rows="13" name="pmbody" cols="54"></textarea><br><br>
<center><input type="Submit" value="Send" name="Submit">&nbsp;&nbsp;<input type="reset" value="Reset" name="Reset"></center>
      </form>
      </p>
            </td>
    </tr>
  </table>


<br />
<div align="center">

</div>



-------------
FeRnAN
http://www.danasoft.com/">



Replies:
Posted By: MadDog
Date Posted: 12 March 2003 at 7:28pm
the problem is your checking for a subject when there isnt a subject field in the form itself.

-------------
http://www.iportalx.net" rel="nofollow">


Posted By: fernan82
Date Posted: 12 March 2003 at 7:30pm

There is a subject field...

Subject: <input type="text" name="pmSubject" size="30" maxlength="41"><br>



-------------
FeRnAN
http://www.danasoft.com/">


Posted By: MKrivanek
Date Posted: 13 March 2003 at 1:08am

Try onSubmit="return CheckForm();"

(adding the semicolon)? i wouldn't think the browser would be that anal... but it's worth a try



Posted By: fernan82
Date Posted: 13 March 2003 at 9:42am
Thanks but it didn't work neither....that's confusing as i use the same code with different forms and it works with some but it don't with some others...

-------------
FeRnAN
http://www.danasoft.com/">


Posted By: ultramods
Date Posted: 16 March 2003 at 3:53am

 Your problem is that you have used a lower case b and an upper case B for pmBody.

//Check for a Message Body
 if (document.frmPMs.pmBody.value ==""){
  errorMsg += "\n\tYou must enter a message body.";
 }

<textarea rows="13" name="pmbody"cols="54"></textarea><br><br>




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net