fabzster 0 Light Poster


I pull data from a MYSQL database to populate a Drop down

            <td class="<?php print $Bank_ca_error;?>">Bank Name</td>
                <select name="Bank" id="Bank" tabindex=24 style="color: <?php print $TextColour;?>"/>
                <option><?php print $_SESSION['Bank_ca'] ;?></option>
                //Get Data to populate drop down
                $BankQuery = "SELECT BankName FROM tblbank ORDER BY BankName";

                $BankResult = mysql_query ($BankQuery);

                        print"<option $nt[BankName]>$nt[BankName]</option>";


I would like based on the value selected populate a text input. So Basically Select the Bank from the List and have it autopopulate the Universal Branch Code in the text input.

I saw an example using Jquery, But I am a complete noob when it comes to this and I cannot get it to work properly

I added the following in the Head section

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

<script type="text/javascript">
        jQuery('#Bank').live('change', function(event) {
                url     : 'getData.php',
                type    : 'POST',
                dataType: 'json',
                data    : $('#myform').serialize(),
                success: function( data ) {
                       for(var id in data) {        
                              $(id).val( data[id] );

I then Added this into the getData.php file


include "../../../includes/dbinfo.inc";

//Connect to database
mysql_connect($db_host, $db_username, $db_password);
@mysql_select_db($db_database) or die("Unable to select database");

$BankName = $_POST['Bank']; // Selected Bank

$query  = "SELECT * FROM tblbank WHERE BankName ='{$BankName}'";
$result = mysql_query($query);
$row = mysql_fetch_array($result)

$BranchCode = $row['UniversalCode'];

$arr = array( 'input#BranchCode' => $BranchCode );
echo json_encode( $arr );


and added the Following to around the inputs and dropdown concerned

<form id='myform'>


I would really appreciate the assistance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.