Re: Detecting which item too select in a select
| From: | Joseph H Blythe | Date: | Wed, 20 Dec 2000 05:18:09 +0000 |
| Subject: | Re: Detecting which item too select in a select | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31158@lists.php.net to get a copy of this message | ||
On Wed, 20 Dec 2000 14:38:01 +1030
Joseph wrote:
JB> hmm, this seems to only return the last array item? so the drop down list has one item
JB> "Ms"
JB>
JB> --snip--
JB>
JB> $sal = array(
JB> "0" => "Mr",
JB> "1" => "Mrs",
JB> "2" => "Miss",
JB> "3" => "Ms");
JB>
JB> while (list($key,$val) = each($sal)) {
JB> $option = '<option value="' . $val . '"';
JB> if ( $my_account["SALUTATION"] == $val ) {
JB> $option .= 'selected ';
JB> }
JB> $option .= '>' . $val . '</option>' . '\n';
JB> }
JB> $tpl->assign('SALUTATION', $option);
JB>
JB> --snip--
JB>
JB> The template has:
JB>
JB> <select name="salutation">
JB> {SALUTATION}
JB> </select>
JB>
JB> $my_account is an array, the key SALUTATION holds VALUE "Mr"
JB>
JB> Any ideas why only the last value of the array is returned?
JB>
I have also tried simular code to set the checked value on a pair of radio buttons, as above it only
will return the last array item, I have read the manual entries for array, list, and each but for
the life of me can't figure out why this is happening?
--snip--
$ok_to_email = array( 0 => "No", 1 => "Yes");
while (list($key,$val) = each($ok_to_email)) {
$radio = '<input type="radio" name="emailMe" value="' . $key .
'"';
if ( $my_account["EMAILME"] == $key ) {
$radio .= ' checked';
}
$radio .= '>' . $val . "\n";
}
$tpl->assign('EMAILME', $radio);
--snip--
Any help would probaly save what is left of my sanity.
Regards
Joseph