Makoto
Makoto

Reputation: 775

message after form validation

I have a JSP page which has several input fields and a servlet validates the fields when I click on the submit button and redirects to another page.

I would like to add a popup window: "all the fields are ok" after a correct server-side validation.

So I started with:

<form ="alert('success');">
 <input type="submit" value="submit">
</form>

The problem is that "success" is printed even if the fields are incorrect.

I thought about setting a parameter in the protected void doPost(HttpServletRequest request,HttpServletResponse response, which calls an execute() function to say if things are OK or not but I do not know how to get this parameter just after the submit so I could make a conditional:

if (checkSubmitParameter == OK )
   callsPopup()

Upvotes: 0

Views: 212

Answers (1)

Trevor
Trevor

Reputation: 13457

Try something like this (see jsfiddle):

<script>
function checkit(){
    var val = document.getElementById('txt').value;
    if(val == "good"){
        alert("success");
    }else{
        alert("failure!");
    }
}    
</script>
<form onsubmit='checkit()'>
    <input type='text' id="txt" />
    <input type='submit' value='Submit' />
</form>

Upvotes: 1

Related Questions