• 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

Validation in JavaScript

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a question regarding validation of javascript:




this code does not work , if I put only one number , form submit successfully, what should I do?
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For one thing your JavaScript code doesn't tell the browser to stop the submission. Have a look over:

https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault
https://github.com/dbhandel/zakas_code/blob/master/Ch14/FormSubmissionExample01.htm
http://stackoverflow.com/questions/3350247/how-to-prevent-form-from-being-submitted#answer-3350351
 
Author
Posts: 22
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avoid setting event handlers in this way:



Instead of specifying inline in your markup, the proper way to do this is to setup an event handler using JS, like this:





Whenever possible, try to keep your markup clean of JS and your JS clean of HTML. Will help with code maintainability.
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JS code :



HTML code :



Please try mentioned code.This will help.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic