• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Only Numeric value allowed

 
Mahesh Mamani
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im afraid not. you will have to use scripting.
 
Charlie Sturman
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Charlie Sturman
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree the input type=text control should have such a std attribute as format.X-Forms will but that is a ways off.
Handy Online Guides including html:
http://www.devguru.com/Technologies/html/quickref/html_input.html#text
 
Mahesh Mamani
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guys,
I think the only option is using JavaScript.

Mahesh
 
Charlie Sturman
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic