File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "what is this doing?" Watch "what is this doing?" New topic

what is this doing?

rich werth
Ranch Hand

Joined: Sep 21, 2001
Posts: 57
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++)

comma=(emptyFields=="")?"":", "
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:
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 ]
I agree. Here's the link:
subject: what is this doing?
It's not a secret anymore!