I'm writing a javascript that checks the user input and validates it as a number, and this is my function:
<script type="text/javascript">
function checkThis(field)
{
if(isNaN(field.value))
{
alert(field.value + ' is an illegal value. Insert a number');
}
}
</script>
Now I want, when the condition is true, restore the last typed value, for example: if the user types 123, then the condition is false, but if the user types 123a then the condition is true and the alert is triggered. I want, after the alert, the value of the field becomes 123.
This is the code of the field:
<input type="text" onkeyup="checkThis(this)" />
Can this be done?