NYCPHP Meetup

NYPHP.org

solved???Re: [nycphp-talk] Remembering which option in a SELECT the user picked.

Tracy tech_learner at yahoo.com
Thu Jan 30 07:44:30 EST 2003


HI,
is this wot u r trying to get???
<!-- select.php -->
<form method="post" action="see.php">
<?
// Dates clubhouse is available
$clubhouseDates = array(
    'Friday August 22, 04:00 PM - 06:00 PM' => 'Friday August 22, 04:00 PM - 06:00 PM',
    'Friday August 22, 06:00 PM - 08:00 PM' => 'Friday August 22, 06:00 PM - 08:00 PM',
    'Friday August 22, 08:00 PM - 10:00 PM' => 'Friday August 22, 08:00 PM - 10:00 PM',
    'Friday August 22, 10:00 PM - 12:00 AM' => 'Friday August 22, 10:00 PM - 12:00 AM',
    'Saturday August 23, 12:00 AM - 02:00 AM' => 'Saturday August 23, 12:00 AM - 02:00 AM',
    'Saturday August 23, 12:00 PM - 02:00 PM' => 'Saturday August 23, 12:00 PM - 02:00 PM',
    'Saturday August 23, 02:00 PM - 04:00 PM' => 'Saturday August 23, 02:00 PM - 04:00 PM',
    'Saturday August 23, 04:00 PM - 06:00 PM' => 'Saturday August 23, 04:00 PM - 06:00 PM',
    'Saturday August 23, 06:00 PM - 08:00 PM' => 'Saturday August 23, 06:00 PM - 08:00 PM',
    'Saturday August 23, 08:00 PM - 10:00 PM' => 'Saturday August 23, 08:00 PM - 10:00 PM',
    'Saturday August 23, 10:00 PM - 12:00 AM' => 'Saturday August 23, 10:00 PM - 12:00 AM',
    'Sunday August 24, 12:00 AM - 02:00 AM' => 'Sunday August 24, 12:00 AM - 02:00 AM',
    'Sunday August 24, 12:00 PM - 02:00 PM' => 'Sunday August 24, 12:00 PM - 02:00 PM',
    'Sunday August 24, 02:00 PM - 04:00 PM' => 'Sunday August 24, 02:00 PM - 04:00 PM'
);

/* Generate the SELECT tag with options.
 * $selectName: Name of the SELECT tag
 * $optionValues: Array containing all the values
 * $selectdValue: Which option gets the SELECTED attribute (pass this function the value 
 *                of the SELECT tag
 */
function generateHtmlSelectTag($selectName, $optionValues, $selectedValue) {
    $str = "<select name=\\"$selectName\\">\
";
    foreach ($optionValues as $key => $value) {
        if ($selectedValue == $value) {
            $str .="<option value=\\"$value\\" selected>$key</option>\
";
        } else {
            $str .= "<option value=\\"$value\\">$key</option>\
";
        }    // End if-else
    }    // End foreach
    $str .= "</select>\
";
    return $str;
}    // End function

// This is called in the PHP file elsewhere to generate the SELECT tag with options
$displaySelectTag = generateHtmlSelectTag("requestTime", $clubhouseDates, ' ');
echo $displaySelectTag; 
?>
<input type=submit value=submit>
</form>

here is the "view source" i got
<form method="post" action="see.php">
<select name="requestTime">
<option value="Friday August 22, 04:00 PM - 06:00 PM">Friday August 22, 04:00 PM - 06:00 PM</option>
<option value="Friday August 22, 06:00 PM - 08:00 PM">Friday August 22, 06:00 PM - 08:00 PM</option>
<option value="Friday August 22, 08:00 PM - 10:00 PM">Friday August 22, 08:00 PM - 10:00 PM</option>
<option value="Friday August 22, 10:00 PM - 12:00 AM">Friday August 22, 10:00 PM - 12:00 AM</option>
<option value="Saturday August 23, 12:00 AM - 02:00 AM">Saturday August 23, 12:00 AM - 02:00 AM</option>
<option value="Saturday August 23, 12:00 PM - 02:00 PM">Saturday August 23, 12:00 PM - 02:00 PM</option>
<option value="Saturday August 23, 02:00 PM - 04:00 PM">Saturday August 23, 02:00 PM - 04:00 PM</option>
<option value="Saturday August 23, 04:00 PM - 06:00 PM">Saturday August 23, 04:00 PM - 06:00 PM</option>
<option value="Saturday August 23, 06:00 PM - 08:00 PM">Saturday August 23, 06:00 PM - 08:00 PM</option>
<option value="Saturday August 23, 08:00 PM - 10:00 PM">Saturday August 23, 08:00 PM - 10:00 PM</option>
<option value="Saturday August 23, 10:00 PM - 12:00 AM">Saturday August 23, 10:00 PM - 12:00 AM</option>
<option value="Sunday August 24, 12:00 AM - 02:00 AM">Sunday August 24, 12:00 AM - 02:00 AM</option>
<option value="Sunday August 24, 12:00 PM - 02:00 PM">Sunday August 24, 12:00 PM - 02:00 PM</option>
<option value="Sunday August 24, 02:00 PM - 04:00 PM">Sunday August 24, 02:00 PM - 04:00 PM</option>
</select>
<input type=submit value=submit>
</form>

<!-- see.php -->
<?
foreach ($_POST as $k => $v)
$$k = $v;
//echo $k, $v;
include ("select.php");
$displaySelectTag = generateHtmlSelectTag("requestTime", $clubhouseDates, $v);
echo $displaySelectTag; 
?>

and when i "view source" see.php i get

<select name="requestTime">
<option value="Friday August 22, 04:00 PM - 06:00 PM">Friday August 22, 04:00 PM - 06:00 PM</option>
<option value="Friday August 22, 06:00 PM - 08:00 PM">Friday August 22, 06:00 PM - 08:00 PM</option>
<option value="Friday August 22, 08:00 PM - 10:00 PM">Friday August 22, 08:00 PM - 10:00 PM</option>
<option value="Friday August 22, 10:00 PM - 12:00 AM">Friday August 22, 10:00 PM - 12:00 AM</option>
<option value="Saturday August 23, 12:00 AM - 02:00 AM">Saturday August 23, 12:00 AM - 02:00 AM</option>
<option value="Saturday August 23, 12:00 PM - 02:00 PM">Saturday August 23, 12:00 PM - 02:00 PM</option>
<option value="Saturday August 23, 02:00 PM - 04:00 PM" selected>Saturday August 23, 02:00 PM - 04:00 PM</option>
<option value="Saturday August 23, 04:00 PM - 06:00 PM">Saturday August 23, 04:00 PM - 06:00 PM</option>
<option value="Saturday August 23, 06:00 PM - 08:00 PM">Saturday August 23, 06:00 PM - 08:00 PM</option>
<option value="Saturday August 23, 08:00 PM - 10:00 PM">Saturday August 23, 08:00 PM - 10:00 PM</option>
<option value="Saturday August 23, 10:00 PM - 12:00 AM">Saturday August 23, 10:00 PM - 12:00 AM</option>
<option value="Sunday August 24, 12:00 AM - 02:00 AM">Sunday August 24, 12:00 AM - 02:00 AM</option>
<option value="Sunday August 24, 12:00 PM - 02:00 PM">Sunday August 24, 12:00 PM - 02:00 PM</option>
<option value="Sunday August 24, 02:00 PM - 04:00 PM">Sunday August 24, 02:00 PM - 04:00 PM</option>
</select>

Tracy


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Coming together is a beginning... 
   keeping together is progress... 
      working together is success !!!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030130/fd1d62bf/attachment.html>


More information about the talk mailing list