CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    IE problem PHP-MYSQL <Select> tag

    Hello,

    You know those bugs that just have no meaning in your code... this is one of them.. hope someone has a solution

    I populate a <select> tag with option tags from a mysql database.. It works PERFECT in FF, Opera, Chrome, Safari but it does not work in IE 6 or 7

    The exact problem

    The data actually gets loaded from the database and i can display it in any <div> i wish.. but it just does not showup in the <select> drop down...

    If i add a manual <option> tag it shows up

    The manual <option> tags are replaced with NOTHING when i populate it from the database here goes the load from the database

    :::Please remember that it works in all Browsers except for IE

    Code:
    echo "<option value='Choose'>Choose</option>";
    while($row = mysql_fetch_array($mcatsresult))
     {
    	echo "<option value=\"" . $row['mcat'] . "\">" . $row['mcat'] . "</option>";
    
    }
    hope someone has an answer

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: IE problem PHP-MYSQL <Select> tag

    Remember that PHP is a server-side language. Therefore, if you are having problems in a certain browser, then PHP is not your problem. It has to be client-side code that is causing the issue.

    That being said, what other code plays in here?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    Re: IE problem PHP-MYSQL <Select> tag

    well.... makes complete sense here goes the html page code

    Code:
    <select class="textbox-width-160" id="mcats" onchange="if(document.getElementById('mcats').value=='Choose'){}else{lodscat('e');}">  </select>
    while for the javascript

    Code:
    function getpagestuff(lang){
    
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
     noajax();
     return
    }
    
    var url="../../pprice-list.php"
    url=url+"?deal=mcats"
    url=url+"&lang="+lang
    xmlHttp.onreadystatechange=reshandler
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    
    	
    }

    and the reshandler is

    Code:
    function reshandler()
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
    
    var Str=xmlHttp.responseText;
    var daArr=Str.split("|");
    
    for(i=0;i<=daArr.length;i++){
    		switch (daArr[i]) 
            {
    		case "mcats":
    			document.getElementById("mcats").innerHTML=daArr[i+1];
    			break;
            }
    }
    } 
    }
    the getXMLHTTPOBJECT is in another file and it is called correctly..

    The data reaches to the case "mcats": successfully..

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: IE problem PHP-MYSQL <Select> tag

    Your problem is that you are invoking GetXmlHttpObject() to initiate the AJAX call. IE uses Microsoft's HTTP XML object. There are two possible ones. Take a look at this W3School's AJAX page for more help.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    Re: IE problem PHP-MYSQL <Select> tag

    my getxmlhttpobject is correct


    here it goes

    Code:
    var xmlHttp
    
    function GetXmlHttpObject()
    {
    
    var xmlHttp=null;
    try
     {
     xmlHttp=new XMLHttpRequest();
    
     }
    catch (e)
    
     {
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    
      }
     catch (e)
    
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    
      }
     }
    return xmlHttp;
    
    }
    
    function noajax(){
    	alert('Your browser does not support AJAX. Please download a new browser');
    }

    the funny thing is that the data is actually loaded and i can show it in a <div> it just does not show in the <select> i hope you still got more ideas..

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: IE problem PHP-MYSQL <Select> tag

    Well, to populate a <select> tag you don't just echo contents...you need to create new options. The following code populates a <select> tag with the id of theSelect from a comma separated file. You can easily adapt this to update from your database.

    Code:
    function populateSelect(url) {
      var theSelect = document.getElementById('theSelect');
      theSelect.length = 0;
    
      var xmlHTTP;
      try{xmlHTTP = new XMLHttpRequest();}
      catch(e) {
        try{xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");}
        catch(e) {
          try{xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");}
          catch(e) {
            alert("Your browser does not support AJAX!");
            return false;
          }
        }
      }
    
      var url = 'page.php';
      xmlHTTP.open('GET', url, true);
      xmlHTTP.send(null);
      xmlHTTP.onreadystatechange = function() {
        if (xmlHTTP.readyState == 4) {
          var theOptions = xmlHTTP.responseText;
          theOptions = theOptions.split(',');
          for (i = 0; i < theOptions.length; i++) {
            theSelect.options[i] = new Option(theOptions[i], theOptions[i]);
          }
        }
      }
    }
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    Red face Re: IE problem PHP-MYSQL <Select> tag

    Wooow its actually working perfectly.. but i am curious to know why does echoing the contents works perfect with all browsers except for IE..


    thanks PeejAvery("");

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    Re: IE problem PHP-MYSQL <Select> tag

    I'm not quite sure about that. It could have something to do with your implementation, or the fact that innerHTML has been deprecated.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  9. #9
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    Re: IE problem PHP-MYSQL <Select> tag

    okays!! if i get the solution i will post it here ..

    have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured