0

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> 
3
  • Please share your code.. it will helps you to get quick answer. Commented Jun 25, 2017 at 10:41
  • sorry, added... Commented Jun 25, 2017 at 10:42
  • 1
    whay are you using <div class="form-group"> in select box? Commented Jun 25, 2017 at 10:45

1 Answer 1

2

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>

Sign up to request clarification or add additional context in comments.

1 Comment

that defaul selected will selected i.imgur.com/yJQJGQv.jpg, i want default selected but not selected, just for notification...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.