Is it possible to have the first item in a dropdown list blank and selected by default but when choosing an item in the dropdown list and hitting submit, having that value stay there.
here is an example
<form action="" method="post" />
<SELECT NAME="whatever" id="whatever">
<?php $selected = isset($_POST["whatever"]) && $_POST["whatever"] == 'whatever'; ?>
<option value="" hidden="true" selected="selected"></option>
<OPTION VALUE=1 onclick"selected='selected'">All</OPTION>
</SELECT>
<input type="submit" name="submit" value="Update"/>
</form>
currently if I hit submit it will change the selected value back to blank.
u may use like this
<form action="" method="post" />
<SELECT NAME="whatever" id="whatever">
<option value="">Select value</option>
<OPTION VALUE=1 <?php if($_POST["whatever"]==1) echo "selected='selected'";?> >All</OPTION>
<OPTION VALUE=2 <?php if($_POST["whatever"]==2) echo "selected='selected'";?> >Value One</OPTION>
</SELECT>
<input type="submit" name="submit" value="Update"/>
</form>
function html_select($name, $options, $selected= "")
{
// open <select> tag, set id & name attributes
$select = "<select id=\"$name\" name=\"$name\">
";
// populate options to drop down list
foreach ($options as $value=> $html) {
$select .= "<option value=\"$value\"";
// select the selected option
if ($value == $selected) {
$select .= " selected=\"selected\"";
}
$select .= ">$html</option>
";
}
// close </select> tag
$select .= "</select>";
// return element
return $select ;
}
echo html_select("whatever", array("" => "Select Value", "1" => "Value 1"), $_POST["whatever"]);
I hope this help.