[thelist] javascript testing for a blank entry in a form

Gary McPherson genyus at ingenyus.net
Tue Jul 8 10:48:03 CDT 2003


> hi gurus,
> 
> i am using the following function to validate a form before
> it is submitted. however it doesnt seem to trap the frm.name being
> blank. 
> 
> help! and thanks in advance.
> 
> code follows
> 
> --------------------------------
> 
> function validate_form( frm )
> {
>  if (frm.name.value == "" )  // doesnt seem to trap empty data.  {
>      alert("Please enter your name.");
>      frm.name.select();
>      return false ;
<snip>

frm.name represents the name attribute of the form, i.e.:
<form name="testForm" method="post" action="page.asp">

So you should never call a form element "name" as it will not be
recognised by Javascript. Change it to "fullname" or something
appropiate and that should solve the problem.

HTH,

Gary




More information about the thelist mailing list