FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

JS being weird

 


DanielXP
This script

Code:
function finialregister(username, password, email, vcode, refered, dd, mm, yyyy, hidedobs, gender, location, aim, msn, surl, pflstatus) {
var registerfrmdiv = document.getElementById('registerfrm');
var dim = parseInt(dimension("registerfrm"));
registerfrmdiv.style.height = "";
xmlfinalreg=GetXmlHttpObject()

var dob = dd+"/"+mm+"/"+yyyy;


   if(xmlfinalreg) {
   xmlfinalreg.open("POST", "<?=$siteurl?>ajax/doregister.php");
   xmlfinalreg.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlfinalreg.onreadystatechange = function() {
      if(xmlfinalreg.readyState == 4 && xmlfinalreg.status == 200) {
      var xmlDocument = xmlfinalreg.responseXML;
      errors = xmlDocument.getElementsByTagName("error");
      msgs = xmlDocument.getElementsByTagName("msg");
      registerfrmdiv.innerHTML = "";
      text = "";
         if(errors.length > 0) {
            text += '<strong>Could not complete registration due to the following errors:</strong><br /><br />';
         var loopIndex;
         for(loopIndex = 0; loopIndex < errors.length; loopIndex++ ) {
            text += '* '+errors[loopIndex].firstChild.data+'<br />';
         }
            text += '<br /><input type="button" style="margin-left:150px;" value="Back" onclick="editreg(\''+username+'\', \''+email+'\', \''+vcode+'\', \''+refered+'\', \''+dd+'\', \''+mm+'\', \''+yyyy+'\', \''+hidedobs+'\', \''+gender+'\', \''+location+'\', \''+aim+'\', \''+msn+'\', \''+surl+'\', \''+pflstatus+'\');" />';
         }else if(msgs.length > 0) {
         
         var loopIndex;
         for(loopIndex = 0; loopIndex < msgs.length; loopIndex++ ) {
            if(loopIndex == 0) {
            text += '<strong>'+msgs[loopIndex].firstChild.data+'</strong><br />';
            }else{
            text += msgs[loopIndex].firstChild.data+'<br />';
            }
            document.getElementById('lgn_uname').value = username;
         }            
         }
      }
   }
   xmlfinalreg.send("username="+username+"&password="+hex_md5(password)+"&email="+email+"&vcode="+vcode+"&refered="+refered+"&dob="+dob+"&hidedobs="+hidedobs+"&gender="+gender+"&location="+location+"&aim="+aim+"&msn="+msn+"&surl="+surl+"&pflstatus="+pflstatus);   
   }
   alert("WTF!");
registerfrmdiv.innerHTML=text;
dim2=parseInt(dimension("registerfrm"));
if(dim) { registerfrmdiv.style.height=dim+"px"; }
if(dim && (dim<dim2 || dim>dim2)){
registerfrmdiv.innerHTML = "<div style='text-align:center'><br /><br /><br /><br /><strong>Please Wait...</strong><br /><br /><img src='<?=$siteurl?>images/loading.gif' /></div>";
}
if(dim<dim2) {
   heightSST(dim, dim2, "registerfrm", true);
}else if (dim>dim2) {
   heightSST(dim, dim2, "registerfrm", false);
}
}


Works fine but if i remove the line with this code on it

Code:
alert("WTF!");


It does not work.

Any ideas?
LukasPu
Dude, this was a bunch of code. It's too much, you should only copy-paste a few lines. Nothing's gonna check your code which is so long Smile I talk from my experience, try to chop your code into parts and search where all the shit starts to go
Peterssidan
The function
Code:
xmlfinalreg.onreadystatechange = function() ...
will be called when state is changed.

Code:
if(xmlfinalreg.readyState == 4 && xmlfinalreg.status == 200)

the code is called when the a correct respond is received.

xmlfinalreg.send is called but if you don't use alert("WTF!"); the whole code will be executed before you get the respond. The send method will not stop the script and wait for a respond. Therefore the text variable will not be set at that time.
DanielXP
Peterssidan wrote:
The function
Code:
xmlfinalreg.onreadystatechange = function() ...
will be called when state is changed.

Code:
if(xmlfinalreg.readyState == 4 && xmlfinalreg.status == 200)

the code is called when the a correct respond is received.

xmlfinalreg.send is called but if you don't use alert("WTF!"); the whole code will be executed before you get the respond. The send method will not stop the script and wait for a respond. Therefore the text variable will not be set at that time.



Thanks sooo much.

I moved the finial bit of code into the status brackets bit.

I can't believe how stupid I was :S (Ps. I had the book "Ajax for dummies" back at the library coz someone booked it out)


Thanks again
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.