You are here: irt.org | FAQ | JavaScript | Form | 3.4 | Q373 [ previous next ]
Try:
<SCRIPT LANGUAGE="JavaScript"><!-- function stripSpaces(x) { while (x.substring(0,1) == ' ') x = x.substring(1); return x; } function empty(x) { if (x.length > 0) return false; else return true; } //--></SCRIPT> <SCRIPT LANGUAGE="JavaScript1.2"><!-- function stripSpaces(x) { return x.replace(/^\W+/,''); } //--></SCRIPT> <FORM NAME="myForm"> <INPUT TYPE="TEXT" NAME="myText"> <INPUT TYPE="BUTTON" VALUE="Test If Empty" onClick="if (empty(stripSpaces(this.form.myText.value))) alert('empty')"> </FORM>