-
April 7th, 2009, 05:20 PM
#1
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
-
April 7th, 2009, 05:39 PM
#2
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.
-
April 7th, 2009, 05:51 PM
#3
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..
-
April 7th, 2009, 06:39 PM
#4
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.
-
April 7th, 2009, 07:04 PM
#5
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..
-
April 7th, 2009, 09:13 PM
#6
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.
-
April 8th, 2009, 03:54 AM
#7
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("");
-
April 8th, 2009, 06:17 AM
#8
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.
-
April 8th, 2009, 07:59 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|