What's wrong with this code? I almost sure that something's wrong with the form's submitting: not getting any of alerts and users are not being created, but can not understand where I made a mistake... APP ID and JS ID cleared for secrecy :)
HTML code has a form and the submit button, form has an ID = registration, button's id = registerForm
Tried to find this problem on the internet and found many variations of submitting the form, but neither helped :(
Parse.initialize("", "");
var currentUser = Parse.User.current();
if(curentUser) {
alert("Already logged in");
}
$(document).ready(function () {
$('#registerForm').click(function(){
$('#registration').submit(function() {
var username = $("#username").val();
var password = $("#password").val();
var email = $("#email").val();
//validation
var errors = "";
if(username === "") errors += "Username required.<br/>";
if(password === "") errors += "Password required.<br/>";
if(email === "") errors += "Email required.<br/>";
if(errors !== "") {
alert("Error!")
return;
}
var user = new Parse.User();
user.set("username", username);
user.set("password", password);
user.set("email", email);
user.signUp(null, {
success: function(user) {
alert("Yay!");
},
error: function(user, error) {
alert("Error: " + error.code + " " + error.message);
}
});
});
});
});
$(document).ready(function(){ $("#registerForm").click(function(){ value = $("#username").attr('value'); alert(value); }); });