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
2010-01-19 03:32:09
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
2010-01-19 03:32:47
+1
A:
Try jquery and use its trim() feature. If someone is inputting spaces, value will be neither null nor length == 0.
Joel Etherton
2010-01-19 03:34:13
thanks. it works
www
2010-01-19 03:51:31
A:
Try this:
if (value.match (/\S/)) { ... }
It will make sure value
has at least 1 non-whitespace character
K Prime
2010-01-19 03:39:38