Hi everyone.
I have two dropdown lists 1 with company name and the other with company branch. when the company name is selected, the value goes into a textbox. when the dropdown box value changes it changes the second dropdown box to find related company branches. i'm having a problem passing the value selected from the second dropdown box to the company branch textbox.How can I do it?
After I click on the first dropdownbox, the second dropdown box would not appear, why this will happen? Why I must click on the submit button, then only the second dropdown box will appear? Anyone can tell me the solution how to solve this problem?
<?php
$region = $country = $state = $city = null; //declare vars
$conn = mysql_connect('localhost', 'root', '');
$db = mysql_select_db('selects',$conn);
if(isset($_GET["region"]) && is_numeric($_GET["region"]))
{
$region = $_GET["region"];
}
if(isset($_GET["country"]) && is_numeric($_GET["country"]))
{
$country = $_GET["country"];
}
if(isset($_GET["state"]) && is_numeric($_GET["state"]))
{
$state = $_GET["state"];
}
if(isset($_GET["city"]) && is_numeric($_GET["city"]))
{
$city = $_GET["city"];
}
?>
<script language="javascript" type="text/javascript">
function CompanyNameCBtoTB(){
document.getElementById("CompanyName").value=document.getElementById("drop_1").value
}
</script>
<script language="javascript" type="text/javascript">
function CompanyBranchCBtoTB(){
document.getElementById("CompanyBranch").value=document.getElementById("drop_2").value
}
</script>
<script language="JavaScript">
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>
<form name="theForm" method="get">
<p>
<!-- REGION SELECTION -->
<select name="region" onChange="autoSubmit();">
<option value="null"></option>
<option value="1" <?php if($region == 1) echo " selected"; ?>>Consonant</option>
<option value="2" <?php if($region == 2) echo " selected"; ?>>Vowel</option>
</select>
<br><br>
<!-- COUNTRY SELECTION BASED ON REGION VALUE -->
<?php
if($region != null && is_numeric($region))
{
?>
<select id="drop_1" name="country" onChange="CompanyNameCBtoTB();">
<option value="null"></option>
<?php
//POPULATE DROP DOWN MENU WITH COUNTRIES FROM A GIVEN REGION
$sql = "SELECT COUN_ID, COUN_NAME FROM COUNTRY WHERE RE_ID = $region";
$countries = mysql_query($sql,$conn);
while($row = mysql_fetch_array($countries))
{
echo ("<option value=\"$row[COUN_ID]\" " . ($country == $row["COUN_ID"] ? " selected" : "") . ">$row[COUN_NAME]</option>");
}
?>
</select>
<?php
}
?>
<br>
<br>
<?php
if($country != null && is_numeric($country) && $region != null)
{
?>
<select id="drop_2" name="state" onChange="CompanyBranchCBtoTB()">
<option value="null"></option>
<?php
//POPULATE DROP DOWN MENU WITH STATES FROM A GIVEN REGION, COUNTRY
$sql = "SELECT STAT_ID, STAT_NAME FROM states WHERE COUN_ID = $country ";
$states = mysql_query($sql,$conn);
while($row = mysql_fetch_array($states))
{
echo ("<option value=\"$row[STAT_ID]\" " . ($state == $row["STAT_ID"] ? " selected" : "") . ">$row[STAT_NAME]</option>");
}
?>
</select>
<?php
}
?>
<input type="submit" name="Submit" value="Submit" />
<?php
if($state != null && is_numeric($state) && $region != null && $country != null)
{
?>
<?php
//POPULATE DROP DOWN MENU WITH CITIES FROM A GIVEN REGION, COUNTRY, STATE
/* $sql = "SELECT CIT_ID, CITY_NAME FROM CITY WHERE STAT_ID = $state ";
$cities = mysql_query($sql,$conn);
while($row = mysql_fetch_array($cities))
{
echo ("<option value=\"$row[CIT_ID]\" " . ($city == $row["CIT_ID"] ? " selected" : "") . ">$row[CITY_NAME]</option>");
}*/
?>
</select>
<?php
}
?>
<input name="CompanyName" type="text" id="CompanyName" value="<?php echo $CompanyName ?>" size="29" />
<input name="CompanyBranch" type="text" id="CompanyBranch" value="<?php echo $CompanyBranch ?>" size="29" />
</form>