Link to home
Start Free TrialLog in
Avatar of jen2483
jen2483

asked on

Textarea validation.

How can I validate a textarea is not empty? I use the code below, but it doesn't work well. Any suggestion? Thanks.

I use the following html code:
<form method="post" action="/EW/forms/form.jsp" id=formRequest name=Form onSubmit="return form_validator(this)">
<table>
<tr>
<td align="center" colspan="2"><textarea name="comments" rows="6" cols="48"> </textarea></td>
</tr>
</table>
</form>

My javascript:
function form_validator(theForm){
if (theForm.comments.value == ""){
               alert("Please provide details.");
      theForm.comments.focus();
      return (false);
      }           
    return (true);
    }
Avatar of devic
devic
Flag of Germany image

<textarea name="comments" rows="6" cols="48"> </textarea>

change to:

<textarea name="comments" rows="6" cols="48"></textarea>
ASKER CERTIFIED SOLUTION
Avatar of GwynforWeb
GwynforWeb
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
but not checks new lines, tabs, special symbols...

and what is very important, it doesn't check the spelling ;)
@Gwyn

do you belive that I didn't answer the question?
have you no shame?