Page 1 of 1
Drop Down Menus
Posted: Thu Nov 27, 2003 1:30 pm
by partiallynothing
I would like to have static drop down menues. First off, I have no clue how to create on without javascript; is there any other way?! Also, I would like them to default to the last user selection (which is stored in a MySQL server). How can I accomplish this? I don't have any code to show you, as I have no clue how to do what I want.

Posted: Thu Nov 27, 2003 1:35 pm
by ghost007
you only need javascript if you want to autosubmit the values. Otherwise you can create the drop down between <POST> tags and add a submit button.
hope this helps
siech
How to create dropdown menu defaulted to last user input
Posted: Mon Dec 01, 2003 7:46 pm
by dyconsulting
If you like drop down to default to last user selection, then you are not talking about static drop downs. You need dynamic drop down. The way to do it is this:
1. Get value of last user selection from database.
2. While building a select list, use value from step 1 to identify which value should be selected.
Here is sample code:
Code: Select all
<?php
function get_default_value () {
$db = mysql_connect ($host, $mysqluser, $mysqlpass);
mysql_select_db ($database,$db);
$query = "select value from user_value";
$val = mysql_query ($query, $db);
$value = mysql_fetch_row ($val);
if (!$value) {
return;
} else
return $value[0];
}
$dropdown = array ("red"=>"RED", "blue"=>"BLUE", "orange"=>"ORANGE");
$selected = get_default_value ();
foreach ($dropdown as $option=>$value) {
$selected = ($option==$selected)? "selected" : "":
echo "<option = '$option' $selected>" . $value. "</option>";
}
?>