Re: building html form select menus from arrays in php

Top Page
Attachments:
Message as email
+ (text/plain)
+ PGP.sig (application/pgp-signature)
Delete this message
Reply to this message
Author: June Tate
Date:  
To: plug-discuss
Subject: Re: building html form select menus from arrays in php
On Mar 6, 2005, at 6:18 PM, Craig White wrote:
> spent a lot of time today on this - researching and can't seem to make
> it work.
>
> <?php
>
> function build_select_box ($picklist) {
>
>   echo '<SELECT NAME="'."drop_list".'">';
>   for ($x=0; $x<count($picklist); $x++) {
>     echo '<OPTION VALUE="'.$picklist[$x].'"';
>     echo '>'.'</OPTION>';
>   }
>   echo '</SELECT>';
> }


On my setup, it seems to work, but without displaying any labels. Your
values are there, but you're not giving a human-readable name for each
option in the select list. As a result, it shows up as a blank list.

Change your <option> HTML to read the following:

    echo '<OPTION>'. $picklist[$x] .'</OPTION>';


And it should display a list the way you're wanting. The value
attribute is only used for enumerated lists where you are mapping
human-readable values to database values (i.e., phone call result
codes). If you don't specify a value attribute, the browser will use
the value between the <option></option> tags as the actual value.

HTH

--
June Tate * http://www.theonelab.com *