A long time ago, I saw a post (that I can't find now) about someone wanting to validate against all blank spaces in their fields... they had done it by using a huge, ugly, long if comparison..
if ((myvar == ' ') || (myvar == ' ') || (myvar == ' ')...) ect.
I was really busy at the time, so I didn't write a response, but I found myself needing the same routine this morning and thought I'd share my solution... (I'll make it a faq after it gets the inevitable polish from you guys...
I tried using a myvar.charCodeAt(i) and looking at each character and setting a flag if all were spaces (32) but for some reason, I couldn't compare against that value... "if (myvar.charCodeAt(i)== 32) " would always show true!? (ie 6)
-Scott
if ((myvar == ' ') || (myvar == ' ') || (myvar == ' ')...) ect.
I was really busy at the time, so I didn't write a response, but I found myself needing the same routine this morning and thought I'd share my solution... (I'll make it a faq after it gets the inevitable polish from you guys...
Code:
form1 = document.forms[0];
myvar = form1.myfield.value ;
if (myvar.length == 0){
alert('Please enter a Description');
form1.myfield.focus();
return false;
} else if (myvar.length > 0){
spaces = '';
for(var i = 0; i < 20; i++){ //20, an arbitrary setting
spaces = spaces + ' ';
if (myvar==spaces){
alert('all spaces');
form1.myfield.focus();
return false;
}
}
}
return true;
I tried using a myvar.charCodeAt(i) and looking at each character and setting a flag if all were spaces (32) but for some reason, I couldn't compare against that value... "if (myvar.charCodeAt(i)== 32) " would always show true!? (ie 6)
-Scott