Hi,

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

Saswati

You obviously don't return the values to the page for display after you handle them.

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.

<html>
<head>
    <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;
        }
        return(returnCode);        
    }
    
    </script>
</head>
<body>
    <form action="./Servlet?QueryString">
        <input type="text" id="txt" name="txt" />
        <br />
        <input type="submit" onclick="return SOS.validate(this.form);" />
    </form>
</body>
</html>

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.

Thank you jwenting. My Problem is solved now.


Saswati

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.