[Site Home] [Forum Home] [Articles] [File DB] [News Archives]

Programming -> Javascript Checkform Not Working.....:(


(View original topic)


bw - Sep-10-2003 server time
QUOTE (fernan82 @ Mar 13 2003, 06:56 PM)
Oh well here's the code:

CODE
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" >
<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">  <input type="reset" value="Reset" name="Reset"></center>
     </form>
     </p>
           </td>
   </tr>
 </table>


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

</div>
</html>



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

You needed to put the submit of the form into the javascript

something like this

add this script at the end of all checks:

if (len(errorMsg)=0)){
form.submit();
}

Delete onSubmit="return CheckForm()" from the
tag

change
into Submit

Red Squirrel - Mar-14-2003 server time
Yep,

MS != consistant roflmao.gif

megaspaz - Mar-14-2003 server time
QUOTE (fernan82 @ Mar 14 2003, 05:50 AM)
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. wink.gif tongue.gif

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

fernan82 - Mar-13-2003 server time
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....

rovingcowboy - Mar-13-2003 server time
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.

pressanykey.gif



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

blink.gif

fernan82 - Mar-13-2003 server time
Looks like it fixed itself unsure.gif

Red Squirrel - Mar-13-2003 server time
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. smile.gif

fernan82 - Mar-13-2003 server time
Oh well here's the code:

CODE
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">  <input type="reset" value="Reset" name="Reset"></center>
     </form>
     </p>
           </td>
   </tr>
 </table>


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

</div>
</html>



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

fernan82 - Mar-13-2003 server time
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:




<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;
}
// -->


PM Groups Mod by Fernan











PM Group Mod by Fernan



Group to PM:



Subject:






  














(Showing 50 last posts, newest on top)