Here is the code that i am trying to get to work
Code: Select all
<?
include("includes/global.inc.php");
include("classes/db.inc.php");
$db = new db();
include("includes/functions.inc.php");
require('js/xajax_core/xajax.inc.php');
$xajax = new xajax();
//$xajax->configure('debug',true);
class myXajaxResponse extends xajaxResponse {
function addCreateOptions($sSelectId, $options) {
$this->script("document.getElementById('".$sSelectId."').length=0");
if (sizeof($options) >0) {
foreach ($options as $option) {
$this->script("addOption('".$sSelectId."','".$option."','".$option."');");
}
}
}
}
$country = $db->select("SELECT * FROM cc_streamrush_iso_countries");
for($i=0;$i<count($country); $i++){
$contry = array($country[$i]['printable_name']);
}
$mode = array(
$contry
);
$transports = array(
'air'=>array('plane','helicopter','air-baloon'),
'water'=>array('boat','watersky','submarine'),
);
$brands = array(
'plane'=>array('Boeing707', 'F-16', 'Columbia'),
'helicopter'=>array('BayWatch Heli', 'Police Heli'),
'air-baloon'=>array('Zeppelin'),
'boat'=>array('Baywatch Safeguard Boat', 'JetBoat'),
'watersky'=>array('JetSky','Board-Sky'),
'submarine'=>array('K-19'),
'motorcycle'=>array("Yamaha", "Harley Davidson", "Ducati"),
'car'=>array("Hummer", "Renault", "Porsche")
);
// adds an option to the select
function addTransports($selectId, $mode) {
global $transports;
$objResponse = new myXajaxResponse();
$data = $transports[$mode];
$objResponse->addCreateOptions($selectId, $data);
// return $objResponse->getXML();
return $objResponse;
}
function addBrands($selectId, $transport) {
global $brands;
$objResponse = new myXajaxResponse();
$data = $brands[$transport];
$objResponse->addCreateOptions($selectId, $data);
//return $objResponse->getXML();
return $objResponse;
}
$xajax->registerFunction("addTransports");
$xajax->registerFunction("addBrands");
$xajax->processRequest();
?>
<?
if (isset($_POST['Submit'])) {
print_r($_POST);
}
?>
<html>
<head>
<title>AJAX Dynamic Drop Down Tutorial</title>
<?
$xajax->printJavascript("js/");
?>
<script type="text/javascript">
function addOption(selectId, val, txt) {
var objOption = new Option(txt, val);
document.getElementById(selectId).options.add(objOption);
}
</script>
</head>
<body>
<?php
?>
<form name="form1" method="POST" action="">
Type :
<select name="type" id="type"
onchange="xajax_addTransports('transports', document.form1.type.value)">
<option value="">--select--</option>
<? foreach ($mode as $mod) { ?>
<option value="<?= $mod?>"><?= $mod?></option>
<? } ?>
</select>
Transportation :
<select name="transports" id="transports"
onchange="xajax_addBrands('brands', document.form1.transports.value)">
<option value="">--select--</option>
</select>
Brands :
<select name="brands" id="brands"><option value="">--select--</option>
</select>
<input type="submit" value="Submit" name="Submit" id="Submit">
</form>
</body>
</html>
Code: Select all
$country = $db->select("SELECT * FROM cc_streamrush_iso_countries");
for($i=0;$i<count($country); $i++){
$contry = array($country[$i]['printable_name']);
}
$mode = array(
$contry
);
$transports = array(
'air'=>array('plane','helicopter','air-baloon'),
'water'=>array('boat','watersky','submarine'),
);
$brands = array(
'plane'=>array('Boeing707', 'F-16', 'Columbia'),
'helicopter'=>array('BayWatch Heli', 'Police Heli'),
'air-baloon'=>array('Zeppelin'),
'boat'=>array('Baywatch Safeguard Boat', 'JetBoat'),
'watersky'=>array('JetSky','Board-Sky'),
'submarine'=>array('K-19'),
'motorcycle'=>array("Yamaha", "Harley Davidson", "Ducati"),
'car'=>array("Hummer", "Renault", "Porsche")
);
does this make any sense?
i guess what i am asking is how can i get the query to represent it self in the $mode area if it is not in the for statement?