Thursday, 15 March 2012

javascript - isNaN not firing until 2 characters are typed in -



javascript - isNaN not firing until 2 characters are typed in -

my html code is:

<input onkeypress="validatea(this.value)" type="text" id="aaa" name="aaa" size="10" placeholder="a"> <span id="aspan" class="validate"> </span>

and javascript is:

function validatea(valueofaaa) { if (isnan(valueofaaa)) { document.getelementbyid('aspan').innerhtml="please come in numerical value."; } else { document.getelementbyid('aspan').innerhtml=""; } }

to clarify, question is:

why innerhtml="please come in numerical value." not firing until 2 letters or numbers typed input box?

change onkeypress() onkeyup() because when keypress triggered, actual value of input not captured yet.

javascript

No comments:

Post a Comment