|
Posted by ED on 11/09/02 11:50
"dude" <dude.j@gmail.com> wrote in message
news:e6u8g5$aau$1@ss408.t-com.hr...
>> try:
>> foreach($_GET['OS'] as $i => $val)
>> echo $i . ": " . $val . "<br>";
>>
>> By the way, I think you're missing the attribute MULTIPLE from the select
>> if you want to be able to select multiple items. It should be
>> <select name="OS[]" size="5" multiple>
>>
>> or if you're using xhtml,
>> <select name="OS[]" size="5" multiple="multiple">
>
> i did set multiple, and the foreach and the echo result is:
> if all the items in the list are selected :
> 0: 1
> 1: 2
> 2: 3
> 3: 3
>
> if second selected then the echo will be: 0: 1
>
> ok, i can work this way, but can it echo values i mean selected string,
> like Windows, Linux, ... , not 0:1, 0:2, etc ...
> is it possible ?
> eccept if ... or switch condition
>
> foreach($_GET['OS'] as $i => $val)
> if($i == 0 && $val == 1)
> echo "Windows <br>";
> if($i == 0 && $val == 2)
> echo "Linux <br>";
> ... etc
>
> this is too complicated, what if i have 40 items in the list :)
>
>
>
>
Looks like you're overcomplicating things.
Just change the options to pass the string instead of an index (unless you
need the indes for something else):
<select name="OS[]" size="5" multiple="multiple">
<option value="" selected>Please select one or more...</option>
<option value="Windows">Windows</option>
<option value="Mac OS X">Mac OS X</option>
<option value="Linux">Linux</option>
</select>
Then
$myarray = $_GET['OS'];
will then give you an array of the selected Strings
cheers,
ED
[Back to original message]
|