<select name='brgylist' id='list'>
                    <?php
                    require_once "connection.php";
                    $result = mysql_query("SELECT `BrgyCode`,`Barangay` FROM `ref Barangay`");
                    while($rec = mysql_fetch_array($result))
                    {
                        echo '<option value="'.$rec['BrgyCode'].'">'.$rec['Barangay'].'</option>';

                    }
                    echo 'The Code selected is '.$rec['BrgyCode'];
                    ?>

                    </select>

I want to store the selected dropdown list to a variable because i will use it to query to output in different dropdownlist. please i need your help on this.

Recommended Answers

Are you asking how you can use the item that the user selects in your <select> to fill another <select> element?

Jump to Post

All 2 Replies

Use the "selected" key word as

<select name='brgylist' id='list'>
<?php
require_once "connection.php";
$result = mysql_query("SELECT `BrgyCode`,`Barangay` FROM `ref Barangay`");
while($rec = mysql_fetch_array($result))
{
echo '<option value="'.$rec['BrgyCode'].'" selected="selected">'.$rec['Barangay'].'</option>';
}

?>
</select>

Are you asking how you can use the item that the user selects in your <select> to fill another <select> element?

Be a part of the DaniWeb community

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