RE: [PHP-DB] Pulling apart select list elements
| From: | John W. Holmes | Date: | Thu, 03 Oct 2002 23:56:42 +0000 |
| Subject: | RE: [PHP-DB] Pulling apart select list elements | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-22209@lists.php.net to get a copy of this message | ||
> I have a <select multiple></select> object named list[] that is
passing
> its
> selected contents to an array. That part works fine. I can use a for
loop
> to
> grab all of the selected items. Where I'm stuck is that I want to get
both
> the value AND the text for any given <option> element and simply
numbering
> the items in the array 1-N based on the number of rows is not
sufficient.
>
> Example:
>
> <select name="itemList[]" multiple>
> <option value="101">PHP For Dummies</option>
> <option value="102">PHP For Professionals</option>
> <option value="103">PHP For Gurus</option>
> </select>
>
> I want to be able to be able to get both the value property (101, 102,
> ...)
> AND the text between the <option></option> tags. Currently, I'm only
> getting
> the text between the <option></option> tags. Is there a PHP function
that
> allows me to get to both?
No, you only get the value="" part. I think your confused, or this isn't
the correct code, when you say your are getting what's between
<option></option> then you're doing something different.
Bottom line, you only get the value part. If you want two values passed,
then use some hidden elements to relate the values.
<input type="hidden" name="itemListtext[101]" value="PHP For
Dummies">
would relate to your first element. So in PHP, you'd have
$_POST['itemList'][0] == 101
and
$_POST['itemListtext'][$_GET['itemList'][0]] == "PHP For Dummies"
If you're using your database correctly, all you should need is the
number, anyhow...
---John Holmes...