procek
procek

Reputation: 121

Cancel Submit button and do JS Code

I have simple form:

            <form id="loginform" name="loginform" action="" method="post">
            <div data-role="fieldcontain">
                <label for="login">Login:</label>
                <input type="text" name="login" id="login" value="" />
            </div>
            <div data-role="fieldcontain">
                <label for="password">Password:</label>
                <input type="password" name="password" id="password" value="" />
            </div>
            <div class="ui-body">
                <fieldset class="ui-grid-a">
                    <div class="ui-block-a"><button type="button" class="exitapp">Close</button></div>
                    <div class="ui-block-b"><button type="submit" id="elogin" onclick="return false;">Login</button></div>
                </fieldset>
    </div>
        </form>

And some code in jQuery Mobile. In case press enter button in Firefox form is not submit - it's great, but in Android Emulator it's submit and it cannot using my JS code :( How can repair this?

Upvotes: 0

Views: 973

Answers (3)

Radu
Radu

Reputation: 8699

$('#loginform').submit(function(e) {
    e.preventDefault();
});

See MDN for more info on preventDefault().

Upvotes: 0

Jasper
Jasper

Reputation: 75993

I have found this to work but I always test on my Android device rather than the emulator...:

<form action"..." method="..." onSubmit="return check_form();">
...
</form>
function ckeck_form() {
    ...
    if (error === true) {
        return false;
    } else {
        return true;
    }
}

Upvotes: 0

genesis
genesis

Reputation: 50966

$("form").submit(function(){
    //do your js code
    return false;
});

Upvotes: 1

Related Questions