Quote:
Originally Posted by rnd me
ok, i called my own bluff here, since i was bored.
does this work for you?
- <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
-
<html>
-
<head>
-
<title> numerical validation test</title>
-
<script type="text/javascript">
-
-
function numbersonly(e,th) {
-
if(!e){ e= window.event; }
-
var key = String.fromCharCode( e.keyCode || e.which );
-
var val = Number( th.value + key ) || 0;
-
return !! (val && val < 999999.99 && val.toFixed(2) ==val );
-
}
-
</script>
-
</head>
-
-
<body>
-
<form>
-
<input name="number" onkeypress="return numbersonly(event,this)">
-
</form>
-
</body>
-
</html>
tested in FF3, IE6
This really works, thanks very much for your help :-)
but backspace key is not working in this. I modified it little to work that keys.
Hope this works in Safari too ;-)
[PHP]
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> numerical validation test</title>
<script type="text/javascript">
function numbersonly(e,th) {
if(!e){ e= window.event; }
if (window.event) {
keys = window.event.keyCode;
}
else if (e) {
keys = e.which;
}
else {
return true;
}
var key = String.fromCharCode( keys );
var val = Number( th.value + key ) || 0;
var flag = !! (val && val < 999999.99 && val.toFixed(2) ==val );
if ((keys==null) || (keys==0) || (keys==8) || (keys==9) || (keys==13) || (keys==27) ) {
return true;
}
else if(flag)
{
return true;
}else{
return false;
}
}
</script>
</head>
<body>
<form>
<input name="number" onkeypress="return numbersonly(event,this)">
</form>
<div id="some"></div><br/>
<div id="some1"></div><br/>
<div id="some2"></div><br/>
</body>
</html>[/PHP]