Forum Moderators: coopster
One way is to create a list of items from a data table, and wrap the items in a form with a radio button on each item. When the button is selected and the form is run you can pass the selected item(s) to your query and display the results stored in the same, or another, data table.
With php you can write javascript the same as you write html.
<script>
<!--
var date = '<?php echo date("Y-m-d");?>';
...
//-->
</scipt>
See the hotscripts [hotscripts.com] for code (it will be in javascript section).
Certainly you can use php to generate the combos, but it will require the page to be submitted as many times as you change the selection.
Hope this helps
Michal Cibor
createfrmObject($frmObjName) function is to pass in the form name as a parameter and create the javascript dynamically.
CreateSelect function is to create the select options.
DataFetch function is to fetch the data from the database.
how do i retrieve the "brand name" (e.g. Sony) item of typeCombo if i select e.g. TV? In other words, how do i retrieve the related items of the combo box.
function createfrmObject($frmObjName){
//Purpose: Create the Javascript Dynamically
$this->CurrectForm= $frmObjName;
$DocElement = "document.".$this->CurrectForm.".region";
echo "<script type=\"text/javascript\" language=\"javascript\">";
echo "<!--\n";
echo "\rfunction changeRegion(obj){\r";
for($i=0;$i<count($this->typeArray);$i++){
echo "\rif(obj.value == '".$this->typeArray[$i]."'){\r";
//echo "\r\t/* Value for the Region Drop Down */\r";
echo "\tdocument.$this->CurrectForm.region.options.length = 0;\r";
echo "\t$DocElement.options[$DocElement.options.length] = new Option('--Select--','--Select--');\r";
for($j=0;$j<Count($this->brandArray);$j++){
if ( $this->cityArray[$i] == $this->regionArray[$j]){
echo "\t$DocElement.options[$DocElement.options.length] = new Option('".$this->regionArray[$j][2]."','".$this->regionArray[$j][0]."');\r";
}
}
echo "\tdocument.$this->CurrectForm.region.disabled = false;\n\r";
echo "\treturn true;\r";
echo "}\r";
}
echo "}\r";
echo "-->\r";
echo "</script>";
$this->CreateSelect();
}
function CreateSelect(){
echo "<select name=\"typeCombo\" size=\"1\" onChange='changeRegion(this)'>\r";
echo "<option value='--Select--'>--Select--</option>\r";
for($i=0; $i < count($this->typeArray);$i++) {
echo "<option value='".$this->typeArray[$i]."'>".$this->typeArray[$i]."</option>";
}
echo "</select>";
echo "<select name=\"brandCombo\" disabled>";
echo "<option value='--Select--'>--Select--</option>";
echo "</select>";
}
function DataFetch() {
//Purpose: Fetch the Data From 2 Different Table and store it in array
// Suggestions: If you have changed the Table Names Please Change it in the sql;
$typeSql="select distinct type from ims_asset order by type";
$typeResult=mysql_query($typeSql);
$this->typeArray=array();
while ($typeRow = mysql_fetch_array($typeResult)){
$this->typeArray[] = $typeRow['type'];
$brandSql="select distinct brand from ims_asset";
$brandResult=mysql_query($brandSql);
$IDz=mysql_num_rows($brandResult);
//echo $IDz;
while($brandRow = mysql_fetch_array($brandResult)){
for($i=0;$i<mysql_num_fields($brandResult);$i++){
$this->brandArray[$IDy][$i] = $brandRow['brand'];
}
$this->brandArray[$IDy][$i]=$typeRow[1];
echo $this->brandArray[$IDy][$i];
$IDy+=1;
}// brand While Loop Ends here;
} // Asset Type Loop End
}// DataFetch Function Ends here