Much appreciated... as you guessed, I have never done this before... (i) the 'juicy text' was part of my attempts to get this to work with a simple example, and (ii) adding the parentheses of course helped - cheers!
If you don't mind I, I pasted in the three files of the test I am trying to do prior to implementing this...
After the user picks the site they are interested in, only the locations on/at that site should be available in the locations pulldown - and so on down the chain - and as pulled out of a PostgreSQL database
The onchange for the site selection list seems to be firing OK, the JS is making and 'calling' the URL for the PHP page just fine with the requsite site identifer (
added a JS 'alert' to 'check'), the PHP page is creating the <option></option> text OK (
ditto),
but the location's selection list is
not being updated with the innerHTML text from the xmlHttp.responsetext
I am guessing this is a syntax issue... if someone is able to look at the code with a practiced eye... :-)
TIA! What a resource... :-)
GREG...
-----------------
'MAIN' PAGE <ajax_test_4.php>
-
-
<html>
-
-
<head>
-
-
<title>Try Adjusting based on Site Selection and PostgreSQL connection</title>
-
-
<script language="JavaScript" src="select_locations.js"></script>
-
-
</head>
-
-
<body>
-
-
<?php
-
-
//set up the PostgreSQL database connection used throughout
-
$db_connect=pg_connect("host=[munge] dbname=[munge] user=[munge] password=[munge]") or die(pg_last_error($db_conn));
-
-
//SUM of SITE data for analytical data showing on web page
-
$SQL_Query = " SELECT d_site.site_id, d_site.site_id_abrev
-
FROM (r_analyteclass INNER JOIN r_testoranalyte ON r_analyteclass.analyte_class = r_testoranalyte.analyte_class) INNER JOIN (((d_site INNER JOIN d_location ON d_site.site_id = d_location.site_id) INNER JOIN d_sample ON d_location.location_id = d_sample.location_id) INNER JOIN d_sampleresult ON d_sample.sample_id = d_sampleresult.sample_id) ON r_testoranalyte.test_or_analyte_id = d_sampleresult.test_or_analyte_id
-
GROUP BY d_site.site_id, d_site.site_id_abrev
-
ORDER BY d_site.site_id
-
";
-
$query_result=pg_query($db_connect, $SQL_Query);
-
$counter=0;
-
while($row_data=pg_fetch_array($query_result)) {
-
$counter+=1;
-
$ary_sites[$counter] = $row_data["site_id"];
-
$ary_abbrevs[$counter] = $row_data["site_id_abrev"];
-
}
-
-
?>
-
-
<h2 align="center" style="color:darkgreen">Try AJAX with [munge] (Analytical) Data out of PostgreSQL</h2>
-
-
<form>
-
-
<b>First, Select a Site:</b><br />
-
-
<select name="sites" onchange="fun_get_locations(this.value)">
-
<?php
-
$counter=0;
-
foreach($ary_sites as $dummy) {
-
$counter+=1;
-
print "<option value=\"".$ary_abbrevs[$counter]."\">".$ary_sites[$counter]."</option>";
-
}
-
?>
-
</select>
-
<br />
-
<br />
-
-
<b>Then, Select a Location:</b><br />
-
<select name="locations">
-
<div id="options_locations">
-
<option>[select the site to populate this pulldown]</option>
-
</div>
-
</select>
-
-
<br />
-
<br />
-
-
</form>
-
-
</body>
-
-
</html>
-
-
-----------------
'JS' PAGE <select_locations.js>
-
-
var xmlHttp;
-
-
function fun_get_locations(str) {
-
-
xmlHttp = fun_get_xmlHttp_object();
-
-
if(xmlHttp == null) {
-
alert("Browser does not support AJAX!");
-
return;
-
}
-
-
var url
-
url = "get_available_locations.php";
-
url = url + "?site_abbrev=" + str;
-
xmlHttp.onreadystatechange = fun_state_changed();
-
xmlHttp.open('GET',url,true);
-
xmlHttp.send(null);
-
alert('url: '+ url);
-
alert('Response: '+xmlHttp.responseText);
-
-
}
-
-
function fun_state_changed() {
-
if(xmlHttp.readystate == 4) {
-
document.getElementByID('options_locations').innerHTML = xmlHttp.responseText;
-
}
-
}
-
-
function fun_get_xmlHttp_object() {
-
-
var xmlHttp = null;
-
-
try {
-
//non-IE, modern browsers
-
xmlHttp = new XMLHttpRequest();
-
}
-
catch (e) {
-
//IE
-
try {
-
//IE 6 & 7
-
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
-
}
-
catch (e){
-
//IE 5.5+
-
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
}
-
-
return xmlHttp;
-
-
}
-
-
-----------------
'PHP' PAGE FOR LOCATION SELECTION <get_available_locations.php>
-
-
<?php
-
-
//grab the site abbreviation value 'off' the URL
-
$site_abbrev = $_GET['site_abbrev'];
-
-
//set up the PostgreSQL database connection used throughout
-
$db_connect=pg_connect("host=Strathmore dbname=strathmore_data user=LAN_access password=Juicy42") or die(pg_last_error($db_conn));
-
-
//SUM of LOCATION data for analytical data showing on web page, for the user-selected site
-
$SQL_Query = " SELECT d_location.location_id
-
FROM (r_analyteclass INNER JOIN r_testoranalyte ON r_analyteclass.analyte_class = r_testoranalyte.analyte_class) INNER JOIN (((d_site INNER JOIN d_location ON d_site.site_id = d_location.site_id) INNER JOIN d_sample ON d_location.location_id = d_sample.location_id) INNER JOIN d_sampleresult ON d_sample.sample_id = d_sampleresult.sample_id) ON r_testoranalyte.test_or_analyte_id = d_sampleresult.test_or_analyte_id
-
WHERE d_site.site_id_abrev = '".$site_abbrev."'
-
GROUP BY d_location.location_id
-
ORDER BY d_location.location_id
-
";
-
$query_result=pg_query($db_connect, $SQL_Query);
-
while($row_data=pg_fetch_array($query_result)) {
-
$locations_at_selected_site[] = $row_data["location_id"];
-
}
-
-
//put the locations into the <select> field for the locations pulldown
-
foreach($locations_at_selected_site as $location_string) {
-
print "<option value=\"$location_string\">$location_string</option>";
-
}
-
-
?>
-
-