McBryver Posted May 24, 2010 Share Posted May 24, 2010 I have a function in a file that in the error log for fire fox says its not defined: errors: Empty string passed to getElementById doNo is not defined The function is on line 83, so why the error? ajax: function getSQLInfo(info){ if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("msg").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","secure/getInfo.php?table="+ type +"&info="+ info,true); xmlhttp.send(); } function login(){ var user = document.getElementById("user").value; var pass = document.getElementById("pass").value; document.getElementById("msg").innerHTML="<img src='secure/images/loading.gif'"; if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); }else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var returi = xmlhttp.responseText; if( returi="forward" ){ window.location = "account.php"; } if( returi="wrong" ){ document.getElementById("msg").innerHTML="Incorrect Login Information!"; } } } xmlhttp.open("GET","secure/login.php?user="+ user +"&pass="+ pass,true); xmlhttp.send(); } function doYes(){ document.getElementById("officermsg").innerHTML="<img src='secure/images/loading.gif'"; if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); }else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var returi = xmlhttp.responseText; document.getElementById("officermsg").innerHTML=returi; } } xmlhttp.open("GET","secure/base.php?yes=1",true); xmlhttp.send(); } function doNo(){ if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); }else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var returi = xmlhttp.responseText; document.getElementById("officermsg").innerHTML=returi; } } xmlhttp.open("GET","secure/base.php?no=1",true); xmlhttp.send(); } function changedivuser(){ document.getElementById('changeuser').innerHTML = '<input type="text" id="username"><input type="submit" onclick="return changerUsername();" value="Change It!">'; } function changerUsername(){ document.getElementById("changeuser").innerHTML = '<img src="pic/loading.gif">'; var name getElementById("username").value; if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); }else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var returi = xmlhttp.responseText; if( returi!="" ){ document.getElementById("msg").innerHTML=""; document.getElementById("changeuser").innerHTML = '<input type="submit" value="Change Username" onclick="return changeUser();">'; document.getElementById("user_name").innerHTML = returi; }else{ document.getElementById("msg").innerHTML="Internal Error Contact Admin!"; } } } xmlhttp.open("GET","secure/changename.php?name="+name,true); xmlhttp.send(); } function getAccountInfo(type){ document.getElementById("msg").innerHTML="<img src='secure/images/loading.gif'"; if(type="user"){ if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); }else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var returi = xmlhttp.responseText; if( returi!="" ){ document.getElementById("username").innerHTML=returi; document.getElementById("msg").innerHTML=""; } } } xmlhttp.open("GET","secure/account.php?" + type + "=1",true); xmlhttp.send(); } if(type="email"){ if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); }else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var returi = xmlhttp.responseText; if( returi!="" ){ document.getElementById("email").innerHTML=returi; document.getElementById("msg").innerHTML=""; } } } xmlhttp.open("GET","secure/account.php?" + type + "=1",true); xmlhttp.send(); } } Quote Link to comment Share on other sites More sharing options...
trq Posted May 24, 2010 Share Posted May 24, 2010 Its likely out of scope from where it is being called. No way I'm digging through all that code to find out however. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted May 24, 2010 Share Posted May 24, 2010 the code indentation is horrid to even look if it is out of scope or not. But here it is with proper indents function getSQLInfo(info) { if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("msg").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", "secure/getInfo.php?table=" + type + "&info=" + info, true); xmlhttp.send(); } function login() { var user = document.getElementById("user").value; var pass = document.getElementById("pass").value; document.getElementById("msg").innerHTML = "<img src='secure/images/loading.gif'"; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var returi = xmlhttp.responseText; if (returi = "forward") { window.location = "account.php"; } if (returi = "wrong") { document.getElementById("msg").innerHTML = "Incorrect Login Information!"; } } } xmlhttp.open("GET", "secure/login.php?user=" + user + "&pass=" + pass, true); xmlhttp.send(); } function doYes() { document.getElementById("officermsg").innerHTML = "<img src='secure/images/loading.gif'"; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var returi = xmlhttp.responseText; document.getElementById("officermsg").innerHTML = returi; } } xmlhttp.open("GET", "secure/base.php?yes=1", true); xmlhttp.send(); } function doNo() { if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var returi = xmlhttp.responseText; document.getElementById("officermsg").innerHTML = returi; } } xmlhttp.open("GET", "secure/base.php?no=1", true); xmlhttp.send(); } function changedivuser() { document.getElementById('changeuser').innerHTML = '<input type="text" id="username"><input type="submit" onclick="return changerUsername();" value="Change It!">'; } function changerUsername() { document.getElementById("changeuser").innerHTML = '<img src="pic/loading.gif">'; var name getElementById("username").value; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var returi = xmlhttp.responseText; if (returi != "") { document.getElementById("msg").innerHTML = ""; document.getElementById("changeuser").innerHTML = '<input type="submit" value="Change Username" onclick="return changeUser();">'; document.getElementById("user_name").innerHTML = returi; } else { document.getElementById("msg").innerHTML = "Internal Error Contact Admin!"; } } } xmlhttp.open("GET", "secure/changename.php?name=" + name, true); xmlhttp.send(); } function getAccountInfo(type) { document.getElementById("msg").innerHTML = "<img src='secure/images/loading.gif'"; if (type = "user") { if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var returi = xmlhttp.responseText; if (returi != "") { document.getElementById("username").innerHTML = returi; document.getElementById("msg").innerHTML = ""; } } } xmlhttp.open("GET", "secure/account.php?" + type + "=1", true); xmlhttp.send(); } if (type = "email") { if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var returi = xmlhttp.responseText; if (returi != "") { document.getElementById("email").innerHTML = returi; document.getElementById("msg").innerHTML = ""; } } } xmlhttp.open("GET", "secure/account.php?" + type + "=1", true); xmlhttp.send(); } } Looking at that its just a bunch of functions don't really see any problem there. Can you show the line that's actually causing the error (the line in firebug or whatever js debugger youre using)? Quote Link to comment Share on other sites More sharing options...
plutomed Posted May 25, 2010 Share Posted May 25, 2010 Is the function defined before it's called? I don't know if this has to be true in JS. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.