• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Only Numeric value allowed

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
im afraid not. you will have to use scripting.
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic