aspose file tools*
The moose likes JSP and the fly likes Ajax jsp form validation problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Ajax jsp form validation problem?" Watch "Ajax jsp form validation problem?" New topic
Author

Ajax jsp form validation problem?

Manas Saxena
Ranch Hand

Joined: Mar 01, 2013
Posts: 38
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

Joined: Jan 10, 2002
Posts: 61063
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Consider Paul's rocket mass heater.
 
subject: Ajax jsp form validation problem?