keep default selected value in bootstrap multiselect

1.3k Views Asked by At

I have use bootstrap multiselect my code is as below,

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

  <option value="100" <?php if($session == "1"){echo "selected";}?>>foo</option>
  <option value="101" <?php if($session2 == "1"){echo "selected";}?>>bar</option>
  <option value="102">bat</option>
  <option value="103">baz</option>
</select>

 $('#data').multiselect({
                     nonSelectedText: 'Select option',
 onDropdownHide: function (event) {}
});

here I have default selected value.on page load it shows me my default selected value.when I select another value (other then default selected). my "multiselect dropdown-toggle btn btn-default" this not append new value with default selected value and override it with new value although checkboxes are still checked.

and when I get value with

$("#data").val(); 

it only gives me value which are newly selected not give me value that I selected default. I want all checked value from dropdown and also all checked value should show in "multiselect dropdown-toggle btn btn-default".

can any body help me for this?I will appreciate best answer.

1

There are 1 best solutions below

3
On

You could try using $_SESSION['variableName'] rather than $session. So that the content value still retain.

You could use this as your reference: http://php.net/manual/en/reserved.variables.session.php