473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

populating a drop down with Ajax? IE problems.

I have a page with google maps up and running. When a user clicks on a location from the map I would like to populate a drop down with data from the database related to that location. I have it up and working wonderful. Well that was what I thought until I tried it is IE. All that I get is an empty drop down. I know the problem is related to filling the element with the xmlHttp.responseText, but no matter how many solution I have tried as suggested by google I still have no luck.

main php page
[php]
<div style="width:330px; height:600px; float:left;">
<div>
<form id="pestForm" action="fruit.php?option=report" method="post">
<fieldset style="width:280px;">
<legend>Pest</legend>
<div id="error"><?php echo $_SESSION[error]; ?></div>
<p>
<label for="pest">Pest</label>
<select style="width:170px;" id="pest" name="pest" >
<option value="">Select Pest</option>
</select>
</p>
<p>
<label for="biodate">Biofix Date</label>
<input type="text" id="biodate" name="biodate" value="<? echo '01/01/' . date('Y'); ?>" size="10" maxlength="10" />
<input type="button" style="border-width: 0px; height: 17px; width: 19px; background-image: url('/img/calendar1.gif');
</p>
<p>
<label for="enddate">End Date</label>
<input type="text" id="enddate" name="enddate" value="<? echo date("m/d/Y"); ?>" size="10" maxlength="10" />
<input type="button" style="border-width: 0px; height: 17px; width: 19px; background-image: url('/img/calendar1.gif');
</p>
<div class="buttonbox">
<input type="submit" name="pSubmit" value="Submit" onclick="if (pestCheck() == false) return false;" />
<input type="reset" />
<input type="button" onclick="location.href='index.php'" value="Back" />
</div>
</fieldset>
</form>
</div>
</div>
[/php]


javascript used when a location is clicked
Expand|Select|Wrap|Line Numbers
  1. // This function is called each time a station marker is added
  2. // it formats the station's tooltip and adds event listeners for click, hover, etc.
  3. function formatMarker(station) {
  4.    var num = station.stn_num;
  5.    var name = station.stn_name;
  6.    var div_width = (7.9 * name.length) + 48;
  7.    if(div_width < 110) div_width = 110;
  8.    station.tooltip = "<div id=\"tooltip\" style=\"width:" + div_width + "px\">Num:"+num+'<br/>Name: ' + name + '</div>';
  9.  
  10.    // Add listener for marker click events
  11.    // if a station icon is clicked, its corresponding id is displayed
  12.    GEvent.addListener(station, "click", function() {
  13.          setPest();
  14.    });
  15.  
  16.    // Add listener for marker hover events
  17.    // if the user hovers over a station icon, information about the station is displayed
  18.    GEvent.addListener(station,"mouseover", function() {
  19.          showTooltip(station);
  20.    });
  21.    GEvent.addListener(station,"mouseout", function() {
  22.          globaltooltip.style.visibility="hidden";
  23.    });
  24.    return station;
  25. }
  26.  
  27. function setPest() {
  28.    var xmlHttp = false;
  29.    try {
  30.       xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  31.    } catch (e) {
  32.       try {
  33.          xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  34.       } catch (e) {
  35.          xmlHttp = false;
  36.       }
  37.    }
  38.  
  39.    if (!xmlHttp && typeof XMLHttpRequest!='undefined') {
  40.       try {
  41.          xmlHttp = new XMLHttpRequest();
  42.       } catch (e) {
  43.          xmlHttp = false;
  44.       }
  45.    }
  46.  
  47.    if (!xmlHttp && windos.createRequest) {
  48.       try {
  49.          xmlHttp = window.createRequest();
  50.       } catch (e) {
  51.          xmlHttp = false;
  52.       }
  53.    }
  54.  
  55.    //xmlHttp.overrideMimeType('text/xml');
  56.  
  57.    var url = "includes/ajax.php";
  58.  
  59.    xmlHttp.onreadystatechange=function() {
  60.       if(xmlHttp.readyState==4) {
  61.          //alert(xmlHttp.resonseText);
  62.             var spanElement = document.getElementById('pest');
  63.             spanElement.innerHTML = '';
  64.             try {
  65.                spanElement.innerHTML = xmlHttp.responseText;
  66.             } catch (e) {
  67.                var wrappingElement = document.createElement('div');
  68.                wrappingElement.innerHTML = xmlHttp.responseText;
  69.                spanElement.appendChild(wrappingElement);
  70.             }
  71.       }
  72.    }
  73.  
  74.    xmlHttp.open("POST",url,true);
  75.    xmlHttp.send(null);
  76. }
  77.  
php code that queries the database includes/ajax.php
[php]
<?php
$query = "SELECT pest_id, name FROM pests;";
$result = pg_query($query);

header("Content-type: text/xml");
$pest .= "<option value=''>Select Pest</option>\n";
while($info = pg_fetch_row($result)) {
$name = htmlentities(trim($info[1]));
$pest .= "<option value='$info[0]' >$name</option>\n";
}

echo $pest;
exit;
?>

[/php]

You help is welcome.

Here is the link if you want to try to see my problem. The error is only seen in IE
http://beta.climate.usurf.usu.edu/fruit.php
May 19 '08 #1
1 1840
acoder
16,027 Expert Mod 8TB
The link isn't working, so can you show how you call formatMarker()?
May 20 '08 #2

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

Similar topics

1
by: msnews.microsoft.com | last post by:
I'd like to hear your thoughts on best methods for populating drop down list controls. I have states and countries drop down lists that don't change often, so naturally I "hard code" them in the...
4
by: Pete Lux | last post by:
I have a drop down that populates on page load. The drop down brings in customer numbers from my local MSDE database. It does this fine, but I click a button that finds quotes for those customers...
3
by: Yi Chen | last post by:
We have a drop down list on a PHP page, with several product names, and when people click one item, we will refresh the same page with the product name as parameter, and in turn we want to include...
1
by: Jeff Gardner | last post by:
Greetings: I have a table with 3 pieces of data that I would like to use to dynamically populate 3 drop downs using javascript. The fields are state, orgname, office. If it's not already...
1
by: Boris Twila | last post by:
I just want to have 1 drop down list fill the other drop down list without a round trip. Is there some really simple ajax thing i can copy and use, or is it a big deal do i habe to install an...
6
by: Rob Meade | last post by:
Hi all, Looking for a bit of help if possible. For about 2 weeks now I've been investigating the best way to populate related drop down menus, and have their values pre-populated again if the...
1
by: JackInDaBox | last post by:
Hello, I am new to this and have run into a small problem. I am using the Ajax toolkit with VS 2005 to fill some drop downs through a web service and it works great. All of the cascading drop...
11
by: tokcy | last post by:
Hi everyone, I am new in php and ajax, i am facing the prob while i click on element of first drop down then in second dropdown all element showl come from database. I mean i have three dropdown 1....
14
by: Philth | last post by:
Hi there, I've essentially got a form with several drop down, each populated by columns in various tables. The populating bit works fine - the column rows appear as they should in the menu. ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.