This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes what is this doing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "what is this doing?" Watch "what is this doing?" New topic
Author

what is this doing?

rich werth
Ranch Hand

Joined: Sep 21, 2001
Posts: 57
Hi
Can anyone tell me what this is doing? This is the whole function and does what it is supposed to do.....Check to see if data is missing in form fields but it doesn't check to see if a user enters in just spaces.
function validateMe(theForm)
{
var emptyFields=""
var size = <%=splitSize%>*5;
for (i=0; i <= size; i++)
{

if(theForm.elements[i].value=="")
{
comma=(emptyFields=="")?"":", "
emptyFields=emptyFields+comma+theForm.elements[i].name}}
{
if (emptyFields!="")
{
alert('All Fields must contain data. \n'+'Please return and complete the form.')
return false
}
}
}
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
I don't know why JavaScript didn't include trim methods on the String object but all is not lost.
The following code adds that functionality to Strings, just paste it somewhere in your script tag, or have it as an include file.
To use the trim functions do something like:
if (document.myForm.myTextbox.trim() == "") {
alert("text must be entered");
}
Here is the code:
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hey, James! That was cool! I didn't know you could extend stuff that way in Javascript. I am so going to be using that.
[ May 02, 2002: Message edited by: Bodie Minster ]
 
Don't get me started about those stupid light bulbs.
 
subject: what is this doing?