Guido Wesdorp wrote on 02 Dec 2003:
Craig wrote:
Is there a way to only allow numeric entry? I tried to add a
onKeyPress, but the problem is I don't think you can have more
than one function per <input..>, or can you?
Sure you can... Just add the event handler to the HTML and it
should work. I think using JavaScript you can actually register
more than one function *per event type*...
Is this what you mean?
<INPUT ... onclick="myFirstFunction();mySecondFunction();[etc...]">
In that example, myFirstFunction(), followed by mySecondFunction(),
followed by...(until the end of the list) would be executed on each
click.
To Craig - a slight syntax error in your example:
<input name="castStation" type="text" value="0"
onChange="valueCalculate()";>
^
That semi-colon shouldn't be there. It doesn't need to be present in
the intrinsic event, either - only if there is more than one
statement.
The best way to cover this really is to just test for NaN and alert
the user. There are too many avenues to cover that can interfere with
other functionality when restricting entry. Instead, do something
like this:
// Returns true if is valid number, false otherwise
//
function isValidNumber( num ) {
return !isNaN( Number( num )));
}
If you only want to validate integers, for example, you could use:
function isValidInt( num ) {
return !isNaN( parseInt( num )));
}
Mike
--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)