Jump to content

Textarea vs Input Validation


Phoenix917

Recommended Posts

Hey, guys!  I have a simple question I can't seem to find the answer to....  If someone's posted it, it won't come up in my results!  I simply want to validate a textarea box as I have input (regular text) boxes in my form.  For some reason, textareas don't seem to like the same coding!  Any suggestions? 

 

I wrote the validation for the textarea the same as I did for my input boxes:

 

 
if (doc.txtComment.value.length == 0)
{
alert("Did you go through all this work for nothing?  I didn't think so.  Please enter a comment.");
doc.txtComment.focus();
doc.txtComment.select();
return false;
}

 

The html for the textarea is:

 

<td><label><div align="left">
          <textarea name="txtComment" cols="30" rows="5" id="txtComment"></textarea>
        </div></label></td>

 

What should be different from the input boxes to make it work?  Thanks!! :)

Link to comment
Share on other sites

technically, the textarea has no "value" attribute, which is why your length always evaluates to 0 (if at all, since that should throw a "property not found" error in JS).  you would probably be more interested in looking at the innerHTML property, for which there's a bit of documentation courtesy of w3schools below:

 

http://www.w3schools.com/htmldom/prop_anchor_innerhtml.asp

 

you can probably find more helpful technical knowledge in a JS reference website, but hopefully this helps you along.

Link to comment
Share on other sites

I just found it!  When you create a textarea, it has automatically has no "type" attribute.  So....  I just added the "type" value and voila! 

 

<td><label><div align="left">
          <textarea name="txtComment" type="text" cols="30" rows="5" id="txtComment"></textarea>
        </div></label></td>

 

I can't believe I finally figured it out!  *sigh*  Newbie overlook...lol...Thanks. :)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.