Hi, Hello I have a text field. Would like to use the user to key in only numeric values. Is there any property in the text field, which sets this. Don't wanna use JavaScript. If no other option then no other go, but to use it. Thanks in advance, Mahesh
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 4095
1
posted
0
im afraid not. you will have to use scripting.
SCJP
Charlie Sturman
Ranch Hand
Joined: Apr 04, 2002
Posts: 112
posted
0
this is really ugly but a select with options can be used to limit input values.The javascript function is only for demonstration.
Mahesh Mamani
Ranch Hand
Joined: Jun 25, 2001
Posts: 110
posted
0
Hi, Thanks for Ur help. In WML there is a property called FORMAT for text field in which we can specify the format reqd(numeric, alphanumeric, and so on)... SO, is there no such property in HTML. Mahesh
Thanks Guys, I think the only option is using JavaScript. Mahesh
Charlie Sturman
Ranch Hand
Joined: Apr 04, 2002
Posts: 112
posted
0
Here is a numericOnly Format option for input text controls, just add onkeypress="formatNumberKp()" in the input type=text tag and include the 2 simple functions.With a little work you could extend this to any browser and any format.
[ April 30, 2002: Message edited by: Charlie Sturman ]
Rob Hunter
Ranch Hand
Joined: Apr 09, 2002
Posts: 788
posted
0
Mahesh, Are you just validating the input for numbers or do you want to allow for number selection only, like suggested with the drop downs? If just validating, using regular expressions is a good choice. Rob
A GPuvathingal
Greenhorn
Joined: May 23, 2002
Posts: 10
posted
0
Hi Mahesh, Though this comes late -- you could try this code ..... <script> function onlyNumeric(){ if( (event.srcElement.type == "text") && isNaN(event.srcElement.value) ) { alert("Enter a numeric value") str = event.srcElement.value truncatedValue = str.substring(0,str.length-1)
if(isNaN(truncatedValue)==false) event.srcElement.value =truncatedValue else event.srcElement.value ="" } } document.onkeyup = onlyNumeric ; </script> This code will make sure every text box in the page allows only numeric values. All the best....