0

I'm making a register/login form in javascript. User should enter information about himself and the computer should put that information into an array and remember it but it 'forgets' it every time I reload the page.

else {
    document.cookie = email;
    cookies[cookies.length] = document.cookie;
    $('#error').text("Your registration is complete.");
    break;
}

...more code

$('.btn').click(function() {
    alert(cookies[cookies.length - 1]);
});

Any ideas to solve this? I have one more question. How can I check weather is an username alerady in use?

Here is the full js code:

var main = function() {

    var people = [];

    var cookies = [];

    $('#register_email').val("");
    $('#register_username').val("");
    $('#register_password').val("");
    $('#register2_password').val("");

    function Person(username, email, password, repeat_password) {
        this.username = username;
        this.email = email;
        this.password = password;
        this.repeat_password = repeat_password;
    }

    $('#register').click(function() {

    var username = $('#register_username').val();
    var email = $('#register_email').val();   
    var password = $('#register_password').val();
    var r_password = $('#register2_password').val();

    if( email==="" || username==="" || password==="" || r_password==="") {
        $('#error').text("You didn't fill everything");
    }

    else {

    people[people.length] = new Person(username, email, password, r_password);

        for(var key in people) {
            //This should check weather this username was used before but I'm not really sure what to insert instead of "name"
            if(people[people.length - 1].username === "name") {
                $('#error').text("This username is already in use");
                break;
            }
            else if(password !== r_password) {
                $('#error').text("Passwords don't match");
                break;
            }
            else {
                document.cookie = email;
                cookies[cookies.length] = document.cookie;
                $('#error').text("Your registration is complete.");
                break;
            }
        }   

    }

    });


$('.btn').click(function() {
    alert(cookies[cookies.length - 1]);
});

};
$(document).ready(main);

There is a js-fiddle live example in comments.

js- m
  • 143
  • 9

0 Answers0