Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 31st, 2005, 10:17 PM   #1
aznluvsmc
Hobbyist Programmer
 
Join Date: Aug 2005
Posts: 137
Rep Power: 3 aznluvsmc is on a distinguished road
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 == "") {
     answer = confirm("No comments entered, are you sure?");
     }
aznluvsmc is offline   Reply With Quote
Old Dec 31st, 2005, 10:22 PM   #2
aznluvsmc
Hobbyist Programmer
 
Join Date: Aug 2005
Posts: 137
Rep Power: 3 aznluvsmc is on a distinguished road
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.
aznluvsmc is offline   Reply With Quote
Old Jan 7th, 2006, 11:59 PM   #3
Uday
Programmer
 
Join Date: Oct 2005
Location: India
Posts: 30
Rep Power: 0 Uday is on a distinguished road
<html>
<head>
<title>Programming forum
</title>
</head>
<script language="javascript">
document.write("ENTER YOUR COMMENT");
function valuetest()
{

	if(test.comment.value=="") 
		{
     		alert("No comments entered");
     		}

}

</SCRIPT>
<form Name="test">
<input type="text" name="comment" value="">
<P><input type="Submit" onClick="valuetest()"></P>
</form>
</body>
</html>

This code need to be linked with CGI script.
Uday is offline   Reply With Quote
Old Jan 8th, 2006, 6:45 AM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jan 8th, 2006, 10:30 AM   #5
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
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.
Cerulean is offline   Reply With Quote
Old Jan 8th, 2006, 12:29 PM   #6
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
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_name

You can also do some weird hacks, but that covers the rudiments.
__________________

tempest is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:07 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC