Before I start, no I have no issues that I can find with semicolons, and I'm passing NO values to the function.
When I try to do function "login()" from the console, it works just fine, but when I click an HTML input button to call it, I get "Uncaught TypeError: object is not a function". This is in Chrome by the way.
var aj=new XMLHttpRequest();
var loginf=document.forms["login"];
var regf=document.forms["reg"];
function login(){
var errors=document.getElementById("login_err");
var errs=[];
var uname=loginf['uname'];
var pass=loginf['pass'];
var unameVal=uname.value;
var passVal=pass.value;
if(unameVal.length<4 && unameVal.length>0){
errs.push("Username too short. Try again please.");
}
else if(unameVal.length>18){
errs.push(innerHTML="Username is too long. Try again please.");
}
else if(unameVal.length==0){
errs.push("Please enter a username.");
}
if(passVal.length<8){
errs.push("Password too short. Try again, please.");
}
else if(passVal.length>30){
errs.push("Password is too long. Try again please.");
}
if(errs.length==0){
aj.onreadystatechange=function(){
if(aj.readyState>=4 && aj.status==200){
if(aj.responseText=="suc"){
window.location="/new.php";
}
}
}
aj.open("POST","/inc/php/core.php",false);
aj.setRequestHeader("Content-type","application/x-www-form-urlencoded");
aj.send("login=true&data="+data);
}
else{
errors.innerHTML="<ul>";
for(var x=0;x<errs.length;x++){
errors.innerHTML+="<li>"+errs[x]+"</li>";
}
errors.innerHTML+="</ul>";
}
}
function reg(){
}
And then the input button..
<input type="button" class="submit" value="Log in" style="width:25%" onclick="login();"/>
I see nothing wrong with the code.
Thank you in advance if you can find Waldo in this code.
jsFiddle HERE: http://jsfiddle.net/6sa7M/2