I am setting a variable in an if...else statement. However, when I try to call the variable in another function, I get the error that the variable is not defined. How can I set a global variable?
function username_check(){
username = $('#username').val();
if(username == "" || username.length < 7 || username.indexOf(' ') > -1){
usernameFilled = 0;
else{
usernameFilled = 1;
}
}
function email_check(){
email = $('#email').val();
if(email == "" || email.indexOf(' ') > -1) {
emailFilled = 0;
}else{
emailFilled = 1;
}
}
function password_length(){
password = $('#password').val();
if(password == "" || password.indexOf(' ') > -1) {
passwordFilled = 0;
}else{
passwordFilled = 1;
}
}
function password_check(){
password2 = $('#password2').val();
password = $('#password').val();
if(password2.length > 7 && password2 == password) {
password2Filled = 1; /**setting the variable**/
}else{
password2Filled = 0;
}
}
function upload(){
if (usernameFilled == 0 || emailFilled == 0 || passwordFilled == 0 || password2Filled == 0) {
alert('All fields are required');
}else{
/**upload to database**/
}