Pregunta

I have an option panel in which the selected name id is set in the database. i would like to select multiple options and set more name id's then one.

The code for the option panel is like this:

<select name="werknemer[]" data-placeholder="Werknemers..." class="chzn-select" id="werknemer" tabindex="4">
            <option value=""></option> 
                <?if($werknemers !=null):foreach($werknemers as $row):?>
                    <option value='<?=$row->idWerknemer;?>'><?=$row->Voornaam;?>&nbsp;(<?=$row->Achternaam;?>)</option> 
                <?endforeach;endif;?>
            </select><br /></div></div>

this works perfect but i would like to select multiple "idWerknemer" in one option value. How do i make this work? i have tried multiple style. but that doesnt post anything.

¿Fue útil?

Solución

<select multiple>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

Your code will become

<select name="werknemer[]" multiple data-placeholder="Werknemers..." class="chzn-select" id="werknemer" tabindex="4">
            <option value=""></option> 
                <?if($werknemers !=null):foreach($werknemers as $row):?>
                    <option value='<?=$row->idWerknemer;?>'><?=$row->Voornaam;?>&nbsp;(<?=$row->Achternaam;?>)</option> 
                <?endforeach;endif;?>
            </select>

Keyword is "multiple". see : http://www.w3schools.com/tags/att_select_multiple.asp

After selecting few values in selectoption, post your form.

You $_POST will look like this:

Array
(
    [werknemer] => Array
        (
            [0] => 1
            [1] => 2
        )

)

See example of checkbox : Multiple checkbox options on a PHP form

Otros consejos

Use multiple attribute

<select multiple="multiple">
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top