function banUser() {
var userToBan = document.getElementById('userToBan').value;
var cid = document.getElementById('chatId').value;
if (userToBan.length <= 0) {
var x = document.getElementById("banerror");
x.innerHTML = "\tEnter the Username of the user you wish to ban!";
return;
}
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var returncode = this.responseText;
if (returncode == "0") {
var x = document.getElementById("banerror");
x.innerHTML = "\t" + userToBan + " successfully banned!";
document.getElementById('userToBan').value = "";
} else if (returncode == "1") {
x = document.getElementById("banerror");
x.innerHTML = "\tMissing Variables";
} else if (returncode == "2") {
x = document.getElementById("banerror");
x.innerHTML = "\t" + userToBan + " does not exist!";
} else if (returncode == "3") {
window.location.href = "main.php";
} else if (returncode == "4") {
x = document.getElementById("banerror");
x.innerHTML = "\t" + userToBan + " is already banned!";
} else if (returncode == "5") {
x = document.getElementById("banerror");
x.innerHTML = "\tAn admin cannot be banned!";
} else if (returncode == "6") {
x = document.getElementById("banerror");
x.innerHTML = "\tCreator can not be banned!";
} else if (returncode == "7") {
x = document.getElementById("banerror");
x.innerHTML = "\tYou must be an Admin or creator to ban a user!";
}
}
}
xhr.open("POST", "processBanUser.php", true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("chatId=" + cid + "&userToBan=" + userToBan);
}
issue with javascript in if/else statement, seeking assistance as it's causing the script to stop working.