1

I am working with js and jquery. I have a test login page I'm working on and seem to be having trouble with the bind on the login button. In Chrome i see that the js file is loading, but when you click on the button it just refreshes the page. It doesn't show the alert section or shake if you enter the incorrect info, and it doesn't redirect to the main page if you enter the correct info. Here is my code:

HTML:

<body>
    <div id="content">

        <section class="ui-widget ui-corner-all">
            <header class="ui-widget-header ui-corner-top">
                Test Login
            </header>

            <div class="ui-widget-content ui-corner-bottom">

                <p class="ui-state-error">Uername / Password Incorrect.</p>

                <form>
                    <div>
                        <label for="username">Username:</label>
                        <input id="username" type="text">
                    </div>

                    <div>
                        <label for="password">Password:</label>
                        <input id="password" type="password">
                    </div>

                    <div>
                        <input id="btnLogin" type="submit" value="Login">
                    </div>
                </form>
            </div>
        </section>
    </div>

    <div class="ui-widget-overlay" style"z-index: 1002;"> </div>

</body>

JS:

$(".ui-state-error").hide();

$("#btnLogin").button()

.bind ("click", function() {
    if($("#username").val() != "test" && $("#password").val() != "test") {
        $(".ui-state-error").show();
        $("#login section").effect("shake", 150);
    }
    else {
        document.location = 'index.html';
    }

    return false;
});
1
  • remove .button() from javascript block Commented Jun 6, 2012 at 17:44

2 Answers 2

2

Try this

$(function(){
    $("#btnLogin").button().bind ("click", function() {
        if($("#username").val() != "test" && $("#password").val() != "test") {
            $(".ui-state-error").show();
            $("#login section").effect("shake", 150);
        }
        else {
            document.location = 'index.html';
        }

        return false;
    });
});
Sign up to request clarification or add additional context in comments.

4 Comments

That did not work. Still doesn't do anything when you click the button. And to pull the jQuery UI formatting I want, I think I do need the .button() call.
for reference, I was pulling the example from here and it works there.
Yes its working on JsFiddle, one thing I could guess is the right binding and I make it on document ready event. I have updated my answer.
That nailed it. Thank you very much!
0

check this: http://jsfiddle.net/Q5YeX/

I think you are not referencing the right jquery UI lib or your are referencing it the wrong way

1 Comment

JQueryUI reference. can you add the whole markup of the page including header section or where you are putting your <script> tags

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.