Simple Validation

Check the length of an input string

Uses the "onchange" event handler: JavaScript is activated after the field is deselected, that is, when you move the focus from the input field to somewhere else.

Enter some text here:

Here's the code:


<form action="javascript:;" name="form1" method="post">

Enter some text here:<br />

<input type="text" length="30" name="textInput" maxlength="25" 
onchange="window.alert('This text string is ' + textInput.value.length + ' characters long.');
textInput.value=''; /* resets the input field value */
return true;" />    /* signals the browser that the execution of the block has ended */

</form>

Note: