0

I am doing a registration page, for my mobile app, and want to check for duplicate usernames entered by the user/client

I have a button on the page that when clicked, checks availability of the username. However I would like to also incorporate that automatically, if not already done so, when the client clicks submit/go to step 3, I want to perform the check for duplicate usernames using Ajax and if there exists a duplicate, then refresh the SAME page with the error message for duplication, else proceed to step 3.

In my HTML file I have some js that does the following:

$("#check-username").click(function() {
(...this works as I am able to click the CHECK button
and see if the username exists)

I have another js file, that is sourced in my HTML that does the following:

submitHandler : function() {
 $("#reg1").hide();
 $("span#step").html("2");
 $("#check-username").click;
 $("#reg3").show();
 scrollTop();
}

When I click on Go to next step which is reg3, It does not do the validation for check-username. Is my method/syntax for calling check-username correct?

2 Answers 2

1
 $("#check-username").click;
                           ^^----- Missing Braces

supposed to be

 $("#check-username").click();
Sign up to request clarification or add additional context in comments.

Comments

0

The problem is you need to go to step 3 only after the validation ajax request returns from the server. You also are going to need to look at the response from the server to see if it's a duplicate. For example:

$("#check-username").click(function() {
    validateUser();
});

function validateUser(){
    return $.ajax({
        url: '/path/to/validate'
    });
}

And your submit handler stuff:

submitHandler : function() {
     $("#reg1").hide();
     $("span#step").html("2");

     validateUser()
        .done(function(r){
            //for example...
            if(r.isValidUser){
                $("#reg3").show();
                scrollTop();
            }
        });
}

1 Comment

Thanks for the instant feedback.

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.