|
Posted by David Haynes on 12/18/83 11:50
dude wrote:
>> 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 :)
>
>
>
>
Why are you using 1, 2, 3, etc. when you want Windows, Linux, etc.?
Perhaps this little example will help:
<?php
if( isset($_GET['OS']) ) {
foreach( $_GET['OS'] as $key => $value) {
printf("Selected %s<br>\n", $value);
}
}
?>
<html>
<head></head>
<body>
<form action="test.php" method="GET">
<select name="OS[]" size="5" multiple>
<option>Windows</option>
<option>Linux</option>
</select>
<input type="submit">
</form>
</body>
</html>
-david-
[Back to original message]
|