I have a jsp page where the user is asked to do certain entries. Now if the user leaves any one of the entires as blank or as a wrong entry and presses the submit button, he gets an alert message.

Now after the user presses okay,, the page entries becomes either blank or null and then the user has to enter everything again.

Can any one help me.

Thanks a ton in advance


9 Years
Discussion Span
Last Post by saswati_mishra

If you are by any chance attaching or calling the validation function to the 'onclick()' event of the 'submit' button, you need to return a value from the validation function to prevent the trip to the server and to make the data in the form fields persist.

    <script type="text/javascript">
    var SOS = {};
    SOS.validate = function(myForm)
        var returnCode = true;
        if(myForm.elements['txt'].value.length == 0)
            alert('YOu need to enter something');
            returnCode = false;
    <form action="./Servlet?QueryString">
        <input type="text" id="txt" name="txt" />
        <br />
        <input type="submit" onclick="return SOS.validate(this.form);" />

Of course I would like to point out here that client side validation sucks and are of no value whatsoever. Real validations are done at the server. The javascript executing on the client is entirely at the mercy of the person sitting in front of the computer on which it is executing, and so client-side code provides precisely zero security.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.