dynamic created list run on IE Opera but not on Firefox and Safari

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raknin
    New Member
    • Oct 2007
    • 82

    dynamic created list run on IE Opera but not on Firefox and Safari

    I am creating a dynamic list on the server using php file,when I run the PHP script in all 4 browsers (IE 6, Firefox 2, opera and safari 3) every think go Ok and the list is created. but when I call the php script from the browser using Ajax, the list is created fine in IE and Opera but on Firefox and safari I got the following error:

    "Warning: mysql_fetch_row (): supplied argument is not a valid MySQL result resource in /home/content/r/a/k/raknin/html/login/create_generic_ listbox.php on line 72"

    The php script as standalone is working smooth. I suspect that it is something to do with the ajax call but I don't know what. I struggle with this issue almost a day.

    Here is my client ajax call:
    Code:
     
    function GetXmlHttpObject(divID,url)
    {
       
    var xmlHttp=null;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      alert("Firefox, Opera 8.0+, Safari");
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    
     if (xmlHttp==null)
     {
       alert("Your browser does not support AJAX!");
       return FALSE;
     }          
       xmlHttp.onreadystatechange = function() {
         if (xmlHttp.readyState == 4 && xmlHttp.status==200) {
     //      alert(xmlHttp.responseText);      
           document.getElementById(divID).innerHTML=xmlHttp.responseText ;
         } 
       };
         xmlHttp.open("GET", url); 
         xmlHttp.send(null);
    }
    And on the server side I have the following code:

    Code:
     mysql_pconnect($HOSTNAME,$DBUSER,$DBPASSWORD) or die("Can not connect to the DB");
      mysql_select_db($DATABASE) or die("can not select DB"); 
      $result=mysql_query($query); 
        $selectList="";
        $selectList=$select_params;
        $selectList=$selectList. '<option value="none">none</option>';      
           
         while(list($name) = mysql_fetch_row($result)) {
             $selectList=$selectList.'<option value="' . $name . '">' .  $name . '</option>';
         }  // End of while
         
         $selectList=$selectList.'</select>';
         print $selectList;
    } else  {
        Echo "Problem occur while building the list" ;
    }
    please advise.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    How is this function called? How are you compiling the URL?

    Comment

    • raknin
      New Member
      • Oct 2007
      • 82

      #3
      The GetXmlHttpObjec t(divID,url) function is called from on onchange event, when user choose option from the list as a resul the PHP part is called from GetXmlHttpObjec t function. The second list that I have problem with its creation is build dynamically using sql as U can see from the PHP part.

      Comment

      • raknin
        New Member
        • Oct 2007
        • 82

        #4
        I found the problem but still don't have solution:

        The problem is in the FireFox if you craete a list and using the onchange event
        when you select a value fromthe list and you want to see what value is selected you get "Undefined"

        Try this simple code in Firefox you got undefined when selected try it on IE and you will get the selected item any sugesstions.:

        Code:
        <html>
        
        <head>
        
        <title></title>
        <script language="javascript" type="text/javascript">
        
        
        function aa(obj) {
        //var x = document.getElementById("xx").options.value;
        var x = obj.options.value;
        alert(x);
        }
        
        </script>
        </head>
        
        <body>
        <select name="Experience" style="width:150px" id='xx' onchange="aa(this)">
          <option value="Novice" selected="selected">Novice</option>
          <option value="Intermidate">Intermidate</option>
          <option value="Expert">Expert</option>
        </select>
        </body>
        
        </html>

        Comment

        • raknin
          New Member
          • Oct 2007
          • 82

          #5
          I found the problem.

          The problem was that in IE the following work:

          document.getEle mentbyID("x").v alue get the selected value but in Firefox it doesn't work.

          so you have explicitly use:

          obj.options[obj.options.sel ectedIndex].value;

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            [CODE=javascript]obj.value[/CODE]
            should work in both of the browsers too :)

            kind regards

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by raknin
              The problem was that in IE the following work:

              document.getEle mentbyID("x").v alue get the selected value but in Firefox it doesn't work.
              document.getEle mentById("xx"). value should've worked as should obj.value. You were trying to get the options array value instead of the select element value.

              Comment

              Working...