Jazuly
Jazuly

Reputation: 321

default select option in multiple select option

is that possible create default select in multiple select options but that default select not selected.

like default notification, when we not select anything will displaying "Nothing Selected".

Default Notification

i want to change that "Nothing Selected" for example with "Select Category"

my code

<select multiple class="selectpicker" data-live-search="true" id="nama_kat" name="nama_kat[]" form="tambahposting">
   <?php foreach ($data2 as $value): ?>
   <div class="form-group">
      <option>
         <?php echo $value['nama_kat'] ?>
      </option>
   <?php endforeach; ?>
</select> 

Upvotes: 0

Views: 58

Answers (1)

Nirav Joshi
Nirav Joshi

Reputation: 2950

You can achieve your result with this example.

You have to add attribute selected which option you want to select by default.

You have to put if condition when you have some value exact match with option value than you can select option by default.

Example

<option value="notification_default" <?php if( $i == 'notification_default'): echo 'selected="selected"'; endif; ?>>Default Notification</option>

You can add this in your option.

<select multiple class="selectpicker" data-live-search="true" id="nama_kat" name="nama_kat[]" form="tambahposting">
      <option value="1">test 1</option>
      <option value="2">test 2</option>
      <option value="3" selected="selected">default notification</option>
      <option value="4">test 4</option>
      <option value="5">test 5</option>
</select>

Upvotes: 2

Related Questions