Jump to content

[SOLVED] using foreach on deselected items


Canman2005

Recommended Posts

Hi all

 

I have a List/Menu which looks lik

 

<select name="users1[]" id="users1[]" multiple="multiple">
<option value="Dolor">Dolor</option>
<option value="Donec">Donec</option>
<option value="Integer">Integer</option>
<option value="Lacus">Lacus</option>
<option value="Leo">Leo</option
</select>

 

Is it possible to use

foreach($_POST['users1'] as $d)

on all items in the List/Menu, despite if they have been selected or not?

 

thanks in advance

 

ed

If I try and submit the form without any being selected, I get

 

Warning: Invalid argument supplied for foreach()

 

whereas I want it to ignore the fact none are selected and just carry through all the values from the List/Menu even the ones which are not selected.

firstly you mean this i guess then what please?

 


<select name="users1[]" id="users1[]" multiple="multiple">

<?php

$array=array("Dolor","Donec","Integer","Lacus","Leo");

foreach($array as $result){
echo"<option value='$result'>$result</option>";
}

?>
</select>

the problem is im unable to do

 

$array=array("Dolor","Donec","Integer","Lacus","Leo");

 

simply because the values in "users1[]" are dynamically added from another List/Menu, its basically javascript passing over the values from one list to another.

try this a shot in the dark sorry.


Please hold down ctl button to selct more then one option please.

<br/><br/>

<select name="users1[]" id="users1[]" multiple="multiple">

<?php

$array=array("Dolor","Donec","Integer","Lacus","Leo");

foreach($array as $result){

echo"<option value='$result'>$result <br></option>";

}

?>
</select>

<br/><br/>

<input type="submit" name="submit" value="SEND!">

<?php

if(isset($_POST['submit'])){

foreach($users1 as $final_result){

	echo "You Selected: $final_result";
}


}

?>

but I don't know what values are being passed over from one List to another, therefore doing

 

$array=array("Dolor","Donec","Integer","Lacus","Leo");

 

would not be possible unless I knew what values the user was going to pass from one to another

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.