I want to make a dropdown list of an array with the method Form::select
. The dropdown is dynamically generated so the selected item can change.
I made this code :
echo Form::select('nomselect',
$noms_sols,
$_GET['id_region'],
array('onchange'=>"",
'id' => 'select_sols',
'selected' => $systeme['nom_sol']));
The dropdown is working but I don't have the selected item that I want. On the last line of the code, I tried something, but it doesn't work.
Is there a way to do it ? Or am I forced to use a foreach
method ? Thanks in advance.
Third parameter of Form::select method is a selected item. In your case value from $_GET['id_region'] should be also in $noms_sols array.
For example this should add selected attribute on option with value 2.
$noms_sols = array("1", "2", "3");
$id_region = $_GET['id_region']; // $id_region == "2"
echo Form::select('nomselect',
$noms_sols,
$id_region);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.