Answer the question
In order to leave comments, you need to log in
How, when choosing one of the option select multiple, put disabled on the others?
There is a select multiple, and when choosing an option with a value of "null", it is necessary that all the others become disabled.
<div class="form-group col-md-6">
<label for="field-1" class="control-label">Клиент</label>
<?php if (is_array($clients)): ?>
<select id="client" class="form-control select2" name="client[]" style="width: 100%;" multiple onchange="ChangeFilters()">
<option value="null" <?= isset($saved_client) && in_array('null', $saved_client) ? 'selected':'' ?> <?= (!isset($saved_client)) && in_array('null', $s_cl) ? 'selected':'' ?>>Без клиента</option>
<?php foreach ($clients as $client): ?>
<option value="<?=$client['ID']?>" <?= isset($saved_client) && in_array($client['ID'], $saved_client) ? 'selected':'' ?> <?= (!isset($saved_client)) && in_array($client['ID'], $s_cl) ? 'selected':'' ?>>
<?php echo $client['NAME']; ?>
</option>
<?php endforeach; ?>
</select>
<?php endif; ?>
</div>
function ChangeFilters() {
$('select#client').each(function () {
var val = $(this).val();
if (val != 'null') {
$('select#client option[value="' + val + '"]').attr("disabled", true);
}
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question