Page 1 of 1

Javascript Checkform Not Working.....:(

Posted: Thu Mar 13, 2003 5:54 pm
by fernan82
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

Javascript Checkform Not Working.....:(

Posted: Thu Mar 13, 2003 5:56 pm
by fernan82
Oh well here's the code:

Code: Select all

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><b>PM Group Mod by Fernan</b></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>

I didn't knew you had to do that to post the code...

Archived topic from Iceteks, old topic ID:359, old post ID:1770

Javascript Checkform Not Working.....:(

Posted: Thu Mar 13, 2003 6:05 pm
by Red Squirrel
Yeah this board supports html, it can come handy, but I always keep an eye out for trouble makers.

As for your code, I'm not sure, I don't really know javascript.


Oh, I moved this to the coding forum. :)

Archived topic from Iceteks, old topic ID:359, old post ID:1771

Javascript Checkform Not Working.....:(

Posted: Thu Mar 13, 2003 8:18 pm
by fernan82
Looks like it fixed itself :unsure:

Archived topic from Iceteks, old topic ID:359, old post ID:1774

Javascript Checkform Not Working.....:(

Posted: Thu Mar 13, 2003 11:54 pm
by rovingcowboy
not sure what the trouble was? it will submit empty form if that is what you want. do you not want it to submit empty form? if so then you need to add line for it to insist there is something in the comment area before it is sent.

you know you seen the forms online that require certin information.

same thing is needing to be done here.

cant remember the code but will look for it and let you know.

mean time you can look for it at javascripts.com i believe that is it.

you can also get the first page 2000 program and use its feature of checking the page before it previews it. then it will say what and where the error is. or if there is any.

it also has the must have filled code in its code sections.

:dosgonebad:



:banghead: :rolleyes: oops i just seen your code has it in there? so am not sure why it did that.?

:blink:

Archived topic from Iceteks, old topic ID:359, old post ID:1780

Javascript Checkform Not Working.....:(

Posted: Fri Mar 14, 2003 12:50 am
by fernan82
Its fixed, i'm not sure why it was doing that, i changed a line of ASP code and then changed it back to what it originally was and next time i ran the script it was working fine so i still have no idea what the prob. was........but now it's working fine....

Archived topic from Iceteks, old topic ID:359, old post ID:1781

Javascript Checkform Not Working.....:(

Posted: Fri Mar 14, 2003 6:50 am
by megaspaz
fernan82 wrote: Its fixed, i'm not sure why it was doing that, i changed a line of ASP code and then changed it back to what it originally was and next time i ran the script it was working fine so i still have no idea what the prob. was........but now it's working fine....
m$ tech. ;) :P

i would occassionally have that same problem with vc++. don't know why it happens, but it does. :blink: :blink:

Archived topic from Iceteks, old topic ID:359, old post ID:1785

Javascript Checkform Not Working.....:(

Posted: Sat Mar 15, 2003 12:08 am
by Red Squirrel
Yep,

MS != consistant :roflmao2:

Archived topic from Iceteks, old topic ID:359, old post ID:1793