I’m creating a webapp using jQueryMobile. When I’m using the app and I click a button it runs the script multiple times.
For example:
I have a submit button:
<input type="submit" id="login-normal" value="Login" />
And I have this JavaScript for debugging on which this error occurs:
$("input#login-normal").live('click',function() {
console.log("Test");
});
On the very first click it works (and it goes to another screen for example), but when I go back to that screen and I click again, it outputs multiple console.logs
- edit
this is the exact code as in my .js file.
$("div#login input#login-normal").live('click',function() {
var email = $("input#email").val();
var password = $("input#password").val();
user.checkUser(email, password, function(exists) {
if (exists) {
$.mobile.changePage("#home", { transition: "slidedown"});
} else {
console.log("Wrong email or password.");
}
});
console.log("Login");
});
user.checkUser is an object from my class User which checks if the user exists in the database (WebSQL). returns true of false on callback.
Can you use
oninstead ofliveand try it like