• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Integer Validation before submitting form

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
i have form and simple text box that accept integer. the name of text box is not static it will change as request parameter,
now i want integer validation on that field i have added onBlur validation but if i inter any non-integer value its give alert saying its not numeric but doesnt prevent user from submitting form.
how can i restrict user from submiiting form only after entering valid numberic value

as name of text box is not fixed i cannot add onSubmit validation

please awaiting your answers /suggestions

Ravi
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you create a css class called say, "only-numbers" then you can add it to the input and then add an onsubmit that looks for all inputs with class "only-numbers" and validates them stopping the submit if the validation fails.
 
ravindra patil
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so while validating how will it get field name which is not going to be fixed
e.g
<input type="Text" name="<%=Day%/>
how will you get value of this input as we dont know whch day it is going to be ?">
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ravindra patil wrote:so while validating how will it get field name which is not going to be fixed
e.g
<input type="Text" name="<%=Day%/>
how will you get value of this input as we dont know whch day it is going to be ?">


See the part in the reply where I said

If you create a css class called say, "only-numbers" then you can add it to the input

Did you see that part?
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To prevent submission, return false from the submit handler.
 
ravindra patil
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Armitage ,

Thanks for you help...it solved my problem created just given class="integer" and in submit getting all elements by that class and validating it...


its good to see there is solution for every problem not in real life but at least in coding .....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic