Click to See Complete Forum and Search --> : Validation - numbers only


sciguyryan
10-05-2003, 03:01 PM
hi all,

could anyone provide a script that will evaluate this:
document.calc.input.value

and prevent any thing other than numbers being entered and also how can i make a textbox read only so its contents cant be changed?


thanks in advance for any help you can offer.

Charles
10-05-2003, 03:22 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input, textarea {display:block}
-->
</style>

<form action="">
<div>
<label>Enter a Number<input type="text" onchange="if (isNaN(this.value)) {alert('That would not appear to be a valid number.'); this.value=''; this.focus()}"></label>
<textarea readonly>Fee, fie, foe, fum</textarea>
<button type="submit">Submit</button>
</div>
</form>

sciguyryan
10-05-2003, 03:43 PM
thanks charles you answered two questions in one!