views:

580

answers:

4

using value.lenght != 0 ..doesn't work for the blank space situation

A: 
document.myForm.myField.value != ""; // or
document.myForm.myField.value.length == 0;

Example:

function isEmpty() {
  alert(document.myForm.myField.value == "");
}

--

<button onclick="isEmpty()">Is Empty?</button>
<form name="myForm">
  <input type="text" name="myField" />
</form>
Jonathan Sampson
A: 

Since you clearly already know how to get the value, I'll skip that bit.

var value; // we'll assume it's defined
if(value) {
    // textarea content is not empty
} else {
    // textarea content is empty
}

'' evaluates to false. Seems simple enough. What blank space situation are you talking about?

Matchu
+1  A: 

Try jquery and use its trim() feature. If someone is inputting spaces, value will be neither null nor length == 0.

Joel Etherton
thanks. it works
www
A: 

Try this:

if (value.match (/\S/)) { ... }

It will make sure value has at least 1 non-whitespace character

K Prime