Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My form won't check the fields...

Status
Not open for further replies.

Smarty

Programmer
Apr 12, 2001
191
BE
I have this javascript function in the head section:

<script language=&quot;javascript&quot;>
function checkform()
{

if (document.mailform.naam.value == &quot;&quot;) or (document.mailform.comment.value == &quot;&quot;) or (document.mailform.email.value == &quot;&quot;)
{
alert(&quot;Make sure all required fields are filled in!&quot;);
return false;
}
else

return true;

}

</script>
-----------
This is my form:
<form action=mailpromo.asp method=post name=mailform onsubmit=&quot;checkform()&quot;>...
<input type=submit value=&quot;Send me that information!&quot;>
</form>
-------------
but when i click on the submit button, the actionpage is always opened even if the checked fields are empty. It seems he won't execute the function...

Can you tell me where i made the mistake?
Thanx,

Smarty

 
why not set the action to &quot;JavaScript:checkform();&quot; and at the end of the checkform function where you are currently returning true, do this instead: (or something simular)

document.mailform.action = &quot;mailpromo.asp&quot;;
document.mailform.submit();

this is the way I do it, so the submit actually launches the validation function, and that is responsible for posting if everything is ok. ?

 
hie
try
<form action=mailpromo.asp method=post name=mailform onsubmit=&quot;return checkform()&quot;>
bye Victor
 
I tried the mzongo's way and it works! thanx mzongo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top