• 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

Ajax jsp form validation problem?

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have made a registration form and i am validating email id and password using ajax.
The ajax is working fine and appropriate message is displayed for wrong entry.Heres the email id sample code:

[code]
Email id<input type="text" size="34" name="email_id" id="email_id" onkeyup="emailval(email_id.value)">

the ajax function emailval calls a jsp page known as regajax which then checks required conditions and prints apt message.

The problem is how will my form know that the entries are wrong since my ajax call simply prints the apt message.Is it possible to return some boolean value from an ajax call which i could pass on to the form.If yes then how do i pass the value returned by ajax method to the form so that if entries are wrong then the form should not be submitted.
If no then what should be my approach.

 
Sheriff
Posts: 67746
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

Manas Saxena wrote: since my ajax call simply prints the apt message.


That's your problem. You're just returning semantic-less text and shoving it into the DOM. Not a good approach,

Rather, submit the Ajax to a servlet (never, ever, ever, ever use a JSP for processing) that returns JSON data (which could be as simple as true or false, or as complex as you like). JavaScript can then set an error message, set a class on the form field that indicates it is error, or do anything else that needs doing.

Relying on JSP for this is a grave mistake.
 
reply
    Bookmark Topic Watch Topic
  • New Topic