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
https://forums.phpfreaks.com/topic/120604-textarea-vs-input-validation/
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.

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. :)

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.