0

My ajax script for loading the second select box, works in firefox and chrome, but internt explorers cant handle it. I call the onChange function from my select box and give the value from the select box to the function.

Code:

function getXMLHTTP() 
{
var xmlhttp;

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

return xmlhttp;
}

function getType(categoryName) 
{       

    var strURL="includes/get.php?c="+categoryName+"&sid="+Math.random();
        var req = getXMLHTTP();

        if (req) {

                req.onreadystatechange = function() {
                        if (req.readyState == 4) {
                                // only if "OK"
                                if (req.status == 200)
                                    {document.getElementById('type').innerHTML=req.responseText;                        
                                } else {
                                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                                }
                        }               
                }           
                req.open("GET", strURL, true);
                req.send(null);
        }       
}

My second question is, is it possible to send the text between the options tag instead of the value in the options tag?

digga
  • 103
  • 2
  • 12

1 Answers1

1

For your 1st question, I assume your if (req) returns false. Which IE version are you using? Try to add debug codes in getXMLHTTP() function to start diagnosing the codes. Try this solution provided by Microsoft: http://msdn.microsoft.com/en-us/library/ms537505(v=vs.85).aspx

I try not to repeat other's answer. Here is the answer for obtaining text in selected option tag : Getting the text from a drop-down box

Community
  • 1
  • 1
Raptor
  • 53,206
  • 45
  • 230
  • 366
  • i tried to use the solution from Microsoft, but it is still not working. For firefox and chrome everythings works perferct, but in IE 9 or 8 it isnt working. – digga Aug 22 '12 at 10:11
  • Didnt work with jquery before, I could try it but I have no idea how to implement the current code in jquery – digga Aug 22 '12 at 10:36