Link to home
Start Free TrialLog in
Avatar of GodDoesntExist
GodDoesntExist

asked on

AJAX validation form error in IE

Hi!

I have this AJAX to make my PHP validation work in real-time.

It's working properly in all web browsers except IE7 and IE8.

IE is popping an error msg:
Row: 71
Error: Unknown runtime error

What am I doing wrong? Tell me if you need more info to help.

The content of getHint.php is nonessential, it's just echoing stuff.

Thanks in advance!
var xmlHttp 
var string
var type
 
function showHint(str) 
{ 
type = str;
 
switch (type)            // Kollar vilken typ
{                        // Är inte kontrollen med, avsluta utan att göra något
case "email":
string = document.getElementById("emailField").value
break;
case "password":
string = document.getElementById("passwordField").value
break;
case "username":
string = document.getElementById("usernameField").value
break;
case "firstname":
string = document.getElementById("firstnameField").value
break;
case "lastname":
string = document.getElementById("lastnameField").value
break;
case "street":
string = document.getElementById("streetField").value
break;
case "zipcode":
string = document.getElementById("zipcodeField").value
break;
case "city":
string = document.getElementById("cityField").value
break;
case "phone":
string = document.getElementById("phoneField").value
break;
 
default:
return;
}
 
if (string.length==0)        // Finns det inget att kolla, töm alla Hint och avsluta
    {
    document.getElementById(type+"Hint").innerHTML = "";
    return;
    }
  
xmlHttp=GetXmlHttpObject(); 
 
if (xmlHttp == null) 
  { 
  alert ("Your browser does not support AJAX!"); 
  return; 
  }  
  
  
var url="gethint.php?"; 
url +="type="+type;
url += "&string="+escape(string);
url +="&sid="+Math.random(); 
xmlHttp.onreadystatechange=stateChanged; 
xmlHttp.open("GET",url,true); 
xmlHttp.send(null);
}  
 
function stateChanged()  
    {  
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="Complete") 
        {  
        document.getElementById(type+"Hint").innerHTML=xmlHttp.responseText; 
        } 
    } 
 
// KONTROLL AV WEBBLÄSARE
 
function GetXmlHttpObject()
    {
    var xmlHttpObject=null;
    try
    {
        //FIREFOX OPERA SAFARI
        xmlHttpObject=new XMLHttpRequest();
    }
    catch (e)
    {
        //IE
        try
        {
            xmlHttpObject=new ActiveXObject("Msxml12.XMLHTTP");
        }
        catch (e)
        {
            xmlHttpObject=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttpObject;
}

Open in new window

Avatar of prokvk
prokvk

Uhm, you have to end your commands with a semicolon ";" sign ...

From the top:

var xmlHttp;
var string;
var type;

etc ...
Avatar of GodDoesntExist

ASKER

Thank you for your response!

But it didnt help. Same error =/
Did you correct all the unterminated commands ? There're more, there are some under those lines I mentioned too
Oh, and instead of that switch, use just:

string = document.getElementById(type + "Field").value;

that switch is criminally awful ;)
Ah, yeah I did. The same problem though =/

Works like a charm in firefox, opera, etc.

Do you have any more ideas?
IE is complaining about row 71:

document.getElementById(type+"Hint").innerHTML=xmlHttp.responseText;
Hmm ... You can try the following, we'll make a little debugging :)

1, Try this:

document.getElementById(type+"Hint").innerHTML = 'testing';

If it's ok ...

2, Then try

alert(xmlHttp.responseText);
1. worked well

2. it was alerting this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

and <div id="error">my field error msg</div>
ASKER CERTIFIED SOLUTION
Avatar of prokvk
prokvk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, im so stupid! Well, I wasnt trying =) I didnt think of it that way ;)

Thank you for your help!
Thank you for your great help and engagement
My problem isnt 100% solved yet. It is still complaining about the <div id="error"></div> im trying to add to my hint element.

If I replace the div with just a text string "hello" its working. But I really want to output a div.

Is there a way I can do that?
DIV is a valid HTML, so there shouldn't be any problem, I dunno why is it not working for you
Ok, weird! Thanks for your help :)