0

I have two select boxes: the first contains all avaible items and the second one contains the items I've selected from the first select box.

$items=$this->Database->getItems();
$mySelect=form_multiselect('addedMaterials', $items, '1', 'id="addedMaterials" multiple="multiple"');

To submit all the items from the second select box I've put this:

function selectAll()
    {
      var selObj = document.getElementById('addedMaterials');
      for (var i=0; i<selObj.options.length; i++) {
        selObj.options[i].selected = true;
      }
    }

So now, I go to the controller, where I want to get the items from the box...

$stuff = $this->input->post('addedMaterials');

My problem is that it only gets the last selected item, not all. How can I get all the items of the select box?

dak
  • 199
  • 1
  • 5
  • 18
  • Hi dak, i don´t know if this can help you, but if you are using jquery, you can try $('#addedMaterials').find('option').attr('selected', 'selected') to select all and $('#addedMaterials').find('option').removeAttr('selected') to remove selection. – Maciel Escudero Bombonato Oct 09 '13 at 23:11
  • the function works fine... I can see how all the items turn selected. What I want to solve is the post... – dak Oct 09 '13 at 23:18
  • can you edit your question and put the HTML code of this select here? – Maciel Escudero Bombonato Oct 09 '13 at 23:26

1 Answers1

1

I've found my solution here: Post values from a multiple select

When we declare the multiple select, the attribute "name" must be name='mySelect[]'. In my case it should be:

    $mySelect=form_multiselect('addedMaterials[]', $items, '1', 'id="addedPrinters" multiple="multiple"');
Community
  • 1
  • 1
dak
  • 199
  • 1
  • 5
  • 18