NYCPHP Meetup

NYPHP.org

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

Webapprentice webapprentice at onemain.com
Thu Jan 30 09:25:04 EST 2003


Yes, I solved it.  Before I was passing 0 for $v.  I had not know about 
the automatic type conversion, so every OPTION tag had the selected 
attribute in it.
I switched over to === in that comparison.

--Stephen

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


Tracy wrote:

>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
>
>
>  
>





More information about the talk mailing list