Solved

AJAX validation form error in IE

Posted on 2009-05-04
14
285 Views
Last Modified: 2013-12-12
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

0
Comment
Question by:GodDoesntExist
  • 8
  • 6
14 Comments
 
LVL 5

Expert Comment

by:prokvk
ID: 24295979
Uhm, you have to end your commands with a semicolon ";" sign ...

From the top:

var xmlHttp;
var string;
var type;

etc ...
0
 
LVL 3

Author Comment

by:GodDoesntExist
ID: 24296128
Thank you for your response!

But it didnt help. Same error =/
0
 
LVL 5

Expert Comment

by:prokvk
ID: 24296190
Did you correct all the unterminated commands ? There're more, there are some under those lines I mentioned too
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 5

Expert Comment

by:prokvk
ID: 24296371
Oh, and instead of that switch, use just:

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

that switch is criminally awful ;)
0
 
LVL 3

Author Comment

by:GodDoesntExist
ID: 24296782
Ah, yeah I did. The same problem though =/

Works like a charm in firefox, opera, etc.

Do you have any more ideas?
0
 
LVL 3

Author Comment

by:GodDoesntExist
ID: 24296804
IE is complaining about row 71:

document.getElementById(type+"Hint").innerHTML=xmlHttp.responseText;
0
 
LVL 5

Expert Comment

by:prokvk
ID: 24297143
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);
0
 
LVL 3

Author Comment

by:GodDoesntExist
ID: 24297373
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>
0
 
LVL 5

Accepted Solution

by:
prokvk earned 500 total points
ID: 24297399
Well I think it is clear now, isn't it ?? You're trying to add a DOCTYPE as html to your HINT element .. ^^
0
 
LVL 3

Author Comment

by:GodDoesntExist
ID: 24297444
Oh, im so stupid! Well, I wasnt trying =) I didnt think of it that way ;)

Thank you for your help!
0
 
LVL 3

Author Closing Comment

by:GodDoesntExist
ID: 31577553
Thank you for your great help and engagement
0
 
LVL 3

Author Comment

by:GodDoesntExist
ID: 24297639
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?
0
 
LVL 5

Expert Comment

by:prokvk
ID: 24297682
DIV is a valid HTML, so there shouldn't be any problem, I dunno why is it not working for you
0
 
LVL 3

Author Comment

by:GodDoesntExist
ID: 24297745
Ok, weird! Thanks for your help :)
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can't find PHP files on account that has WordPress 3 28
maybe no no httpd.conf 6 48
PHP AJAX Wordpress 9 21
MySQL Sub-Select Query Returning Duplicate Result 7 31
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question