Here is another option for you to sample.

The function takes two parameters, one is the name of the list box, the other is the value to be initally selected. The second parameter is optional, if not present, no value will be inially selected. I do not remember where I picked this up, but I have used it many times.

---------------------------------------------------
function MakeStateDropMenu($Name,$Selected=""){

$StateDropMenu=<<<StateDropMenu
<select name="$Name">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>

StateDropMenu;
if ($Selected){
$StateDropMenu = preg_replace("|\"$Selected\">*|","\"$Selected\" selected>",$StateDropMenu);
}
return $StateDropMenu;
}
---------------------------------------------------
To call function from page:
<?php
echo MakeStateDropMenu("states","$selectedstate");
?>

Guy Haynes


Steven Kallstrom wrote:
I have a drop down list with all fifty states. very common. I conjured
up a way to store the value when you return to edit the form, but there
most be an easier way either in html, or in php. Here is what I
currently have.
<select name="state">
<option value="AL"{$stateselected['AL']}>Alabama</option>
<option value="AK"{$stateselected['AK']}>Alaska</option>
<option value="AZ"{$stateselected['AZ']}>Arizona</option>
.
</select>
$stateselected['$state'] is an array that stores the state that was
selected on the prior form. is there an easier way, to have a default
state picked out of this drop down list.???
Thanks,
Steven Kallstrom


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to