Javascript Checkform Not Working.....:(

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
fernan82
Posts: 16
Joined: Wed Jan 22, 2003 3:20 am

Javascript Checkform Not Working.....:(

Post 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
fernan82
Posts: 16
Joined: Wed Jan 22, 2003 3:20 am

Javascript Checkform Not Working.....:(

Post 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
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

Javascript Checkform Not Working.....:(

Post 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
Honk if you love Jesus, text if you want to meet Him!
fernan82
Posts: 16
Joined: Wed Jan 22, 2003 3:20 am

Javascript Checkform Not Working.....:(

Post by fernan82 »

Looks like it fixed itself :unsure:

Archived topic from Iceteks, old topic ID:359, old post ID:1774
User avatar
rovingcowboy
Posts: 1504
Joined: Wed Dec 18, 2002 10:14 pm

Javascript Checkform Not Working.....:(

Post 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
roving cowboy/ keith
fernan82
Posts: 16
Joined: Wed Jan 22, 2003 3:20 am

Javascript Checkform Not Working.....:(

Post 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
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

Javascript Checkform Not Working.....:(

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

Javascript Checkform Not Working.....:(

Post by Red Squirrel »

Yep,

MS != consistant :roflmao2:

Archived topic from Iceteks, old topic ID:359, old post ID:1793
Honk if you love Jesus, text if you want to meet Him!
Locked