Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax jsp form validation problem?

 
Manas Saxena
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic