I have a function that creates a drop-down menu and fills it with the names of companies found in the PARTNERS table. I also have a javascript onChange event that will post that selected company to a 'users' table in the 'partner_assigned' column. Works great, but how do I pre-load that saved data if it exists or let them select a company if nothing exists. Also, if company exists and is pre-loaded, the user might want to change the company to another, so that option has to be available too. Oye!
Here's my working (albeit not doing everything I want) function:
Code: Select all
function partners_dynamic_menu() {
include ("../_includes/_connect.php");
$query = "SELECT company_name FROM partners ORDER BY company_name ASC";
$result = mysqli_query($con, $query);
echo "<form id=\"partner_assigned\" method=\"post\"> ";
echo "<select id=\"partner_assigned\" name=\"partner_assigned\" class=\"dropmenu200\" onChange=\"selectChange(this.value)\" \">" ;
echo "<option selected=\"selected\">Select Partner</option>";
while($row = mysqli_fetch_array($result)) {
echo "<option value=\"".$row['company_name']."\">".$row['company_name']."</option>" ;
}
echo "</select>";
echo "</form>";
}