0

I am trying to print an error message when email is taken Using Jqueryvalidation but when I enter email which is not taken, the error message won't go away.

please help!

html

<form id="valid" method="post">
        <input type="email" name="emailinput">
        <br><br>
        <input type="submit">
    </form>

javascript

$("#valid").validate({

            rules : {
                emailinput:{
                    minlength:4,
                    required:true,
                    remote: {
                    type: "POST",
                    url: 'UserValidation'//servlet
                    }
                }

                }
    })

    })

servlet

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uname = request.getParameter("emailinput");

        boolean status = user_data.isEmailAvailable(uname);
        System.out.println(status);
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        if(status)
        {

            response.getWriter().println("\"\"");
        }
        else
            response.getWriter().println("{\"true\"}");

    }

I am sure about the servlet, it is working as expected

enter image description here

1 Answer 1

0

You need to use the submitHandler option to define a function that you'll run whenever the inputs are valid.

For readability, you can also use the invalidHandler to house your code for handling bad inputs. (TBH I can't even see how you're handling the response from rules.emailInput.remote, but then the .remote option isn't covered in the docs I found.)

Sign up to request clarification or add additional context in comments.

1 Comment

From Servlet I was returning "{true}" when an email is available but It should return "true" so two brackets were causing trouble

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.