B
B
BuBux2020-05-12 22:30:55
JavaScript
BuBux, 2020-05-12 22:30:55

How to clear select multiple field?

<select id="direction" class="selectpicker form-control" name="direction[]" data-width="100%" multiple>
    <?php foreach ($directions as $direction): ?>
        <option value="<?=$direction['ID']?>" <?= isset($saved_direction) && in_array($direction['ID'], $saved_direction) ? 'selected':'' ?> <?= (!isset($saved_direction)) && in_array($direction['ID'], $s_dr) ? 'selected':'' ?>>
            <?php echo $direction['NAME']; ?>
        </option>
    <?php endforeach; ?>
</select>


$("#direction").val('default');
$("#direction").selectpicker("refresh");

5ebaf952deeda821055858.png
The checkbox (choice) is removed from the values, but the selected options are still visually displayed. I'm using Bottstrap 3 version.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2020-05-12
@BuBux

$('.selectpicker').selectpicker('deselectAll');

$('.selectpicker').selectpicker('val', ''); // если не сработает, попробуйте так

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question