![]() |
How to check a <textarea> field in Javascript?
Hi,
I created a little form on my website that contains a textarea for users to enter comments. Upon clicking submit, my validation function will check various things. I would like to check to see if the user entered anything in the comments section. If they didn't, I'd like to pop-up a confirm dialog box asking if they're sure they want to submit with no comments. The problem is that I'm not sure how the if condition should look like to check the field. I tried the following but it doesn't seem to work. The <textarea> is named comment and there is no default value for it. :
if (form.comment.value == "") { |
Sorry, please ignore this. I found out I have an odd problem on my form. I need to also use a regular expression to check for spaces in the comments. :)
|
:
<html>This code need to be linked with CGI script. |
Not only is that code far more complicated than it should be, it's also wrong. Your function doesn't return anything.
Oh, and don't use document.write. |
And remember to open your body tags (you have a closing one, strangely enough), and not mix uppercase and lowercase tags, or just don't even use uppercase tags. Tag soup is bad.
|
Just for future reference, in case anyobdy searches for this later... the basic ways to access a form are:
:
document.forms["form_name"]["input_name"]:
document.forms[form_index][input_index]:
document.forms.form_name.Input_nameYou can also do some weird hacks, but that covers the rudiments. |
| All times are GMT -5. The time now is 11:25 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC