Forum Moderators: open
Here is the part of the dropdoen menu code:
<select name="province" class="propsearchLONG" id="province" onchange="javascript:updateDisplay('town', 'province', 'updateTownCombo')">
<option selected value="-">...</option>
</select> Here is the part of the data file:
header('Content-Type: text/xml');
header('Content-Disposition: inline; filename=status.xml');if($_GET['a'] == "province"){
mysql_select_db($database_myconection, $myconection);
$quer2=mysql_query("SELECT DISTINCT province,provinceid FROM province WHERE provincecountryid = '".$_GET['country']."' order by province");
$prov = "";
while($noticia = mysql_fetch_array($quer2))
{
$prov .= "
<province>
<code>".$noticia['provinceid']."</code>
<name>".$noticia['province']."</name>
</province>
";
}
echo "<provinces>$prov</provinces>";
}
function updateDisplay(pUpdateWhat, pComboRead, pCallbackFunction) {
//PURPOSE: Decide what elements are going to be updated on the page.//Base url of XML feeds
var url = "data.php?";
//Decide what URL to use
switch(pUpdateWhat) {
case "province":
url = url + "a=province&country=" + comboSelectedValue(pComboRead);
break;
case "town":
url = url + "a=town&province=" + comboSelectedValue(pComboRead);
break;
case "urban":
url = url + "a=urban&town=" + comboSelectedValue(pComboRead);
break;
case "proptype":
url = url + "a=proptype&country=" + comboSelectedValue(pComboRead);
break;
}
url = url + "&time=" + new Date().getTime(); //IE Cache Prevention
//Create AJAX request
var request = null;
try {
request = new XMLHttpRequest();
} catch (tryms) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (otherms) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}
//Check AJAX is initialised
if (request == null) {
alert("Error initialising AJAX");
}
//Send the AJAX request
request.open("GET", url, true);
request.onreadystatechange = function () {
if (request.readyState == 4) {
if (request.status == 200) {
eval(pCallbackFunction + '(request.responseXML)');
}
}
}
request.send(null);
}
//COMBO UPDATES
function updateProvinceCombo(pXML) {
updateComboBox("province", "- Any -", "provinces", "province", pXML);
}
function updateTownCombo(pXML) {
updateComboBox("town", "- Any -", "towns", "town", pXML);
}
function updateUrbanCombo(pXML) {
updateComboBox("urban", "- Any -", "urbans", "urban", pXML);
}
function updatePropTypeCombo(pXML) {
updateComboBox("ptyp", "- Any -", "proptypes", "proptype", pXML);
}
//COMBO BOX SUPPORT PARTS
function updateComboBox(pElementName, pElementDefault, pRootName, pItemsName, pXML) {
//PURPOSE: Clear combo and add XML records in pre-determined format
//Update ANY combobox
comboClear(pElementName)
comboAddOption(pElementName, "-", pElementDefault);
//Process XML document
var xmlDoc = pXML;
var root = xmlDoc.getElementsByTagName(pRootName)[0];
var items = root.getElementsByTagName(pItemsName);
//Cycle Through adding items to combo
for (var i = 0; i < items.length; i++) {
var branch = items[i];
var pcode = branch.getElementsByTagName("code")[0].firstChild.nodeValue;
var pname = branch.getElementsByTagName("name")[0].firstChild.nodeValue;
//Add To Combo Box
//alert(pcode + " " + pname);
comboAddOption(pElementName, pcode, pname);
}
}
function comboAddOption(cmbElement, optionlabel, optionvalue) {
//PURPOSE: Add option to combo box
var opt = document.createElement('option');
opt.value = optionlabel;
opt.text = optionvalue;
var cmb = document.getElementById(cmbElement);
try {
cmb.add(opt, null); // standards compliant
} catch(ex) {
cmb.add(opt); // IE only
}
}
function comboClear(cmbElement) {
//PURPOSE: Clear all options from combo box
i = 0;
var cmb = document.getElementById(cmbElement);
cmb.options.length=0;
}
function comboSelectedValue(cmbElement) {
//PURPOSE: Select an existing combo box
var sindex = document.getElementById(cmbElement).selectedIndex;
var sval = document.getElementById(cmbElement).options[sindex].value;
return sval;
}
//DAYS OF MONTH PARTS
function updateDays(readfrom, writeto) {
//Reference Page Elements
var el = document.getElementById(readfrom);
var wt = document.getElementById(writeto);
var dv = el.value;
//Get selected dateparts
var parts = dv.split("-");
var daysMonth = 32 - new Date(parts[1], parts[0]-1, 32).getDate();
alert(daysMonth);
//Clear list
for (var i = wt.options.length-1; i>=0; i--) {
wt.options[i] = null;
}
wt.selectedIndex = -1;
//Add Blank
var opt = document.createElement("OPTION");
opt = new Option("...", "...");
opt.id = "-";
wt.add(opt);
//Fill List
for (var i = 1; i<=daysMonth; i++) {
opt = new Option(i, i);
opt.id = i;
wt.add(opt);
}
}
Thanks