467,915 Members | 1,847 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

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:
Expand|Select|Wrap|Line Numbers
  1.  
  2. function GetXmlHttpObject(divID,url)
  3. {
  4.  
  5. var xmlHttp=null;
  6. try
  7.   {
  8.   // Firefox, Opera 8.0+, Safari
  9.   xmlHttp=new XMLHttpRequest();
  10.   alert("Firefox, Opera 8.0+, Safari");
  11.   }
  12. catch (e)
  13.   {
  14.   // Internet Explorer
  15.   try
  16.     {
  17.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  18.     }
  19.   catch (e)
  20.     {
  21.     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  22.     }
  23.   }
  24.  
  25.  if (xmlHttp==null)
  26.  {
  27.    alert("Your browser does not support AJAX!");
  28.    return FALSE;
  29.  }          
  30.    xmlHttp.onreadystatechange = function() {
  31.      if (xmlHttp.readyState == 4 && xmlHttp.status==200) {
  32.  //      alert(xmlHttp.responseText);      
  33.        document.getElementById(divID).innerHTML=xmlHttp.responseText ;
  34.      } 
  35.    };
  36.      xmlHttp.open("GET", url); 
  37.      xmlHttp.send(null);
  38. }
  39.  
And on the server side I have the following code:

Expand|Select|Wrap|Line Numbers
  1.  mysql_pconnect($HOSTNAME,$DBUSER,$DBPASSWORD) or die("Can not connect to the DB");
  2.   mysql_select_db($DATABASE) or die("can not select DB"); 
  3.   $result=mysql_query($query); 
  4.     $selectList="";
  5.     $selectList=$select_params;
  6.     $selectList=$selectList. '<option value="none">none</option>';      
  7.  
  8.      while(list($name) = mysql_fetch_row($result)) {
  9.          $selectList=$selectList.'<option value="' . $name . '">' .  $name . '</option>';
  10.      }  // End of while
  11.  
  12.      $selectList=$selectList.'</select>';
  13.      print $selectList;
  14. } else  {
  15.     Echo "Problem occur while building the list" ;
  16. }  
  17.  
please advise.
Mar 13 '08 #1
  • viewed: 1752
Share:
6 Replies
acoder
Expert Mod 8TB
How is this function called? How are you compiling the URL?
Mar 14 '08 #2
The GetXmlHttpObject(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 GetXmlHttpObject function. The second list that I have problem with its creation is build dynamically using sql as U can see from the PHP part.
Mar 15 '08 #3
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.:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3.  
  4. <head>
  5.  
  6. <title></title>
  7. <script language="javascript" type="text/javascript">
  8.  
  9.  
  10. function aa(obj) {
  11. //var x = document.getElementById("xx").options.value;
  12. var x = obj.options.value;
  13. alert(x);
  14. }
  15.  
  16. </script>
  17. </head>
  18.  
  19. <body>
  20. <select name="Experience" style="width:150px" id='xx' onchange="aa(this)">
  21.   <option value="Novice" selected="selected">Novice</option>
  22.   <option value="Intermidate">Intermidate</option>
  23.   <option value="Expert">Expert</option>
  24. </select>
  25. </body>
  26.  
  27. </html>
  28.  
Mar 15 '08 #4
I found the problem.

The problem was that in IE the following work:

document.getElementbyID("x").value get the selected value but in Firefox it doesn't work.

so you have explicitly use:

obj.options[obj.options.selectedIndex].value;
Mar 15 '08 #5
gits
Expert Mod 4TB
Expand|Select|Wrap|Line Numbers
  1. obj.value
should work in both of the browsers too :)

kind regards
Mar 15 '08 #6
acoder
Expert Mod 8TB
The problem was that in IE the following work:

document.getElementbyID("x").value get the selected value but in Firefox it doesn't work.
document.getElementById("xx").value should've worked as should obj.value. You were trying to get the options array value instead of the select element value.
Mar 16 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by netclectic | last post: by
4 posts views Thread by Ian Richardson | last post: by
3 posts views Thread by steffen haugk | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.