i have simple form having elements like name,address, and email , i have to validate them for e.g name must not contain special character.... how can i do this in struts using java script... please help me...
But relying on the user to click "validate" before submitting the form seems like a Really Bad Idea.
And regardless, you still can't ignore server-side validation.
Joined: Aug 16, 2010
am new to struts n this forun also so thanks for replying..really
You call a validate method onclick the same way you'd call a submit method. If you return a boolean false from the validate method, and return the results of the validate method in your onclick, the form won't be submitted. So onclick="return validate(this);" or however you're going to call it.
Tom Varga wrote:I hope the following example will help you:
Note that as a user I really don't appreciate receiving my validation messages one at a time: better to accumulate them and give them to me all at once. Also not a fan of pop-up validation messages, because then they go away when the dialog is gone and I no longer have the requirements available to me unless they're already on the page.
Joined: Aug 16, 2010
thank you for such a nice example sir ... now i can write script i have one question to you sir.. i have one for function that called on submit buttion for calling action class now how can i cal this function too
Like I said: call the validate statement, return boolean false from it if validation fails, and return that value from your onclick attribute.
Joined: Aug 09, 2010
Do not use the onclick event of the submit button for form validation, use only the onsubmit event of the form. The onsubmit event is fired when the user clicks on a submit button in the form ( a form may have more than one submit button).
The onsubmit event is cancelable, if it is canceled, the form will not be sent. If the event handler for the onsubmit event returns false, the event is canceled.
You no need to call the submit method of your form, if you use the onsubmit event for form validation. Simply return true, if the form is valid and return false if it isn't.