I have a script whereby the script is pulldown menu. My problem is... when I click select (or 1st pulldown menu) I will select the data like Raleigh, Durham.... when I clicked it.... the area pulldown menu will show the data if there is.
My question is if say I click Durham and no value in 2nd pull down menu, how can I remove the Area wording with the pulldown menu from the page? Thanks!
( shortly say... I dun want to see the Area wording and 2ndpulldown menu displayed. Unless there is a data in 2ndpulldown menu, then only show Area wording and pulldownmenu
There are three parts..
1) Database.... pls dump the script into ur db
2) JSDropDown.class.php
3) JSDropDown.php
/////////////////////////////////////////////1) Database
#
# Table structure for table `citymaster`
#
# Creation: Jan 07, 2005 at 12:49 AM
# Last update: Jan 07, 2005 at 12:49 AM
#
CREATE TABLE `citymaster` (
`city_id` int(11) NOT NULL auto_increment,
`cityname` varchar(100) default NULL,
PRIMARY KEY (`city_id`),
UNIQUE KEY `city_id` (`city_id`)
) TYPE=MyISAM AUTO_INCREMENT=6 ;
#
# Dumping data for table `citymaster`
#
INSERT INTO `citymaster` VALUES (1, 'Raleigh');
INSERT INTO `citymaster` VALUES (2, 'Durham');
INSERT INTO `citymaster` VALUES (3, 'Hillsborough');
INSERT INTO `citymaster` VALUES (4, 'Chapell Hill');
INSERT INTO `citymaster` VALUES (5, 'Cary');
# Table structure for table `region`
#
# Creation: Jan 07, 2005 at 12:49 AM
# Last update: Jan 07, 2005 at 12:49 AM
#
CREATE TABLE `region` (
`rid` int(11) NOT NULL auto_increment,
`city_id` int(11) NOT NULL default '0',
`region_name` varchar(250) NOT NULL default '',
PRIMARY KEY (`rid`)
) TYPE=MyISAM AUTO_INCREMENT=6 ;
#
# Dumping data for table `region`
#
INSERT INTO `region` VALUES (1, 4, 'NC');
INSERT INTO `region` VALUES (2, 1, 'North Raleigh');
INSERT INTO `region` VALUES (3, 1, 'Northwest Raleigh');
INSERT INTO `region` VALUES (4, 1, 'Downtown Raleigh');
INSERT INTO `region` VALUES (5, 1, 'SouthEast Raleigh');
/////////////////////////////////////////////////////////////////////////////////////2. JSDropDown.class.php
<?
class JSDropDown{
//Member varible Declaration
var $db_con;
var $rs_row;
var $ERR_MSG;
var $regionArrayResult;
// Declare Array Variable;
var $cityArray;
var $regionArray;
// Declare a variable for Assigning the Current Form Name
var $CurrectForm;
function JSDropDown($dbConfig){
//Purpose: Constructer to Handle Database And Value initialize
$this->db_con=mysql_connect($dbConfig['server'],$dbConfig['username'],$dbConfig['password']) or die(mysql_error());
mysql_select_db($dbConfig['database'],$this->db_con) or die(mysql_error($this->db_con));
// Declare the variables as Array
$this->regionArray=array();
$this->cityArray = array();
}
function close_JSDropDown_database(){
//Purpose: Close the Database Connectivity
mysql_close($this->db_con);
}
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;
$citySql="select * from citymaster";
$cityResult=mysql_query($citySql);
$IDx=0;$IDy=0;$IDz=0;
$this->regionArrayResult=array();
while ($cityRow = mysql_fetch_array($cityResult,MYSQL_BOTH)){
for($i=0;$i<mysql_num_fields($cityResult);$i++){
$this->cityArray[$IDx][$i] = $cityRow[$i];
}
$regionSql="select * from region WHERE city_id='".$cityRow["city_id"]."'";
$regionResult=mysql_query($regionSql);
$IDz=mysql_num_rows($regionResult);
while($regionRow = mysql_fetch_array($regionResult)){
for($i=0;$i<mysql_num_fields($regionResult);$i++){
$this->regionArray[$IDy][$i] = $regionRow[$i];
}
$this->regionArray[$IDy][$i]=$cityRow[1];
$IDy+=1;
}// Region While Loop Ends here;
$IDx+=1;
} // City Region Loop End
}// DataFetch Function Ends here
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->cityArray);$i++){
echo "\rif(obj.value == '".$this->cityArray[$i][0]."'){\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->regionArray);$j++){
if ( $this->cityArray[$i][0] == $this->regionArray[$j][1]){
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=\"city\" size=\"1\" onChange='changeRegion(this)'>\r";
echo "<option value='--Select--'>--Select--</option>\r";
for($i=0;$i<count($this->cityArray);$i++){
echo "<option value='".$this->cityArray[$i][0]."'>".$this->cityArray[$i][1]."</option>\r";
}
echo "</select> Area ";
echo "<select name=\"region\" disabled>\r";
echo "<option value='--Select--'>--Select--</option>\r";
echo "</select>\r";
}
} // Class JSDropDown Ends Here
?>
////////////////////////////////////////////////////////////////////////////////////////////////////// 3. JSDropDown.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Dynamic Drop Down, Loads Value With out refreshing Page (Data from Database)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style4 { font-size: 12px;
font-family: Tahoma;
}
-->
</style>
</head>
<body>
<h5><span class="style1">Dynamic Drop Down, Loads Value With out refreshing Page (Data from Database)</span></h5>
<h5><?php
// Script to Query the Concerts Table to Display the results
/* database configuration */
$dbConfig['type']="mysql";
$dbConfig['server']="localhost";
$dbConfig['username']="root";
$dbConfig['password']="";
$dbConfig['database']="testing";
include_once("JSDropDown.class.php");
$frmObjName="JSddForm";
echo "<form name=\"$frmObjName\" action=\"manual.htm\" method=\"post\">";
$JSdd = new JSDropDown($dbConfig);
$JSdd->DataFetch(); // Call the Function which will fetch the data.
$JSdd->createfrmObject($frmObjName); // Pass the Current Form name as the parameter
$JSdd->close_JSDropDown_database();
echo "<input type=\"submit\" name=\"Submit\" value=\"Submit\">";
echo "</form>";
?>
</h5>
<p class="style4">To Check Online Help : <a href="Manual.htm">Click Here </a></p>
<p><span class="style4"><strong><gobinathm at gmail dot com> </strong><strong> </strong></span></p>
</body>
</html>
//////////////////////////////
HOpe someone can help me... Thanks!