0

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>
2
Contributors
3
Replies
7
Views
5 Years
Discussion Span
Last Post by rainny
0

You already have value in drop1 and drop2, then why you want to save same value in another textbox. What is the use?

Edited by urtrivedi: n/a

0

change this line and see the result

<select id="drop_1" name="country" onChange="CompanyNameCBtoTB();autoSubmit();">

0

Hi,the purpose I want the value store in textbox is because I want to append the value from dropdown box inside the textbox. By the way, I had tried to change the line and it works, the second dropdown box will appear without clicking the submit button. But, the problem is the value inside the first textbox fade away every time I click on the first dropdown box. Possible to fix it?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.