954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Ajax Problem - Not working in IE, works perfect in Firefox

Howdy Everyone,

I've been banging my head against this for a bit now and have been reading all kinds of things - but, everything I try has failed. So, I thought I'd ask.

I've just begun working with Javascript/Ajax .. in the last day to try and accomplish a task but, I can't seem to get this code to work in IE it works fine in Firefox.

Perhaps someone can enlighten me - Basically, this is calling back from a php file that updates from a database to choose dropdowns/checkbox based on the users choices.

Any help is greatly appreciated.

function getSex(theSex, myParent){
        var ajaxRequest;
        try{
            ajaxRequest = new XMLHttpRequest();
        } catch (e){
            try{
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try{
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e){
                    alert("Your browser broke!");
                    return false;
                }
            }
        }
        ajaxRequest.onreadystatechange = function(){
            if(ajaxRequest.readyState == 4){
                responcer = ajaxRequest.responseText.split(",");
                size = responcer.length - 1;
                myParent.age.innerHTML = "";
                for(i = 0; i < size;i++)
            if(responcer[i] != "")
              myParent.age.innerHTML += '<option value="' + responcer[i] + '">' + responcer[i] + '</option>';
            }
        }
        ajaxRequest.open("GET", "test.php?theSex=" + theSex, true);
        ajaxRequest.send(null); 
    }
  
  
    function getBelt(theId, myParent){
        var ajaxRequest;
        try{
            ajaxRequest = new XMLHttpRequest();
        } catch (e){
            try{
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try{
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e){
                    alert("Your browser broke!");
                    return false;
                }
            }
        }
        ajaxRequest.onreadystatechange = function(){
            if(ajaxRequest.readyState == 4){
                responcer = ajaxRequest.responseText.split(",");
                size = responcer.length - 1;
                myParent.second.innerHTML = "";
                for(i = 0; i < size;i++)
            if(responcer[i] != "")
              myParent.second.innerHTML += '<option value="' + responcer[i] + '">' + responcer[i] + '</option>';
            }
        }
        ajaxRequest.open("GET", "test.php?id=" + theId, true);
        ajaxRequest.send(null); 
    }
	
	
	
	
	 function getReg(theBelt, myParent){
        var ajaxRequest;
        try{
            ajaxRequest = new XMLHttpRequest();
        } catch (e){
            try{
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try{
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e){
                    alert("Your browser broke!");
                    return false;
                }
            }
        }
        ajaxRequest.onreadystatechange = function(){ 
            if(ajaxRequest.readyState == 4){
                responcer = ajaxRequest.responseText.split(",");
                size = responcer.length - 1;
                document.getElementById("third").innerHTML = "";
                for(i = 0; i < size;i++)
				
            if(responcer[i] != "")
			
              document.getElementById("third").innerHTML += '<input type="checkbox" name ="third[]" value="' + responcer[i] + '">' + responcer[i] + '</input>';
			}
        }
        ajaxRequest.open("GET", "test.php?theBelt=" + theBelt, true);
        ajaxRequest.send(null); 
    }

-Steven

Zanzertuchi
Newbie Poster
3 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

It's not the problem of coding, tell me which version of IE you are currently using

Lizapotter
Newbie Poster
11 posts since Dec 2008
Reputation Points: 10
Solved Threads: 2
 
It's not the problem of coding, tell me which version of IE you are currently using


Howdy,

Thanks for the reply :)

Most importantly I've been trying to get it working in IE7, but I've also tried in IE8 - With the same results.

Zanzertuchi
Newbie Poster
3 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

The issue is that IE does NOT support using the .innerHTML property to *Set* the content of a Select List. (see bug report below)

http://webbugtrack.blogspot.com/2007/08/bug-274-dom-methods-on-select-lists.html

This is broken in IE6, 7 and 8 (and has been noted by Microsoft as a "wont fix" bug)

For IE you'll need to use a workaround setting either the outerHTML, or wrap the .innerHTML in a bogus element like a DIV first. (yeah very silly, but it works)

xyzweb
Newbie Poster
6 posts since Jan 2008
Reputation Points: 10
Solved Threads: 1
 

Thank you for the response,

That is indeed very silly; it'd be nice if everything worked consistently wouldn't it!

Either way, thank you for helping me realize exactly what the problem was, much appreciated.

Zanzertuchi
Newbie Poster
3 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You