<div class="form-group"><label for="unit_of">Unit of Measure</label>
<select class="form-control-sm selectpicker" multiple="multiple" id="unit_of" name="unit_of[]" data-selected-text-format="count">
<?php $sql = "select * from unit_of";
$res = mysqli_query($db_handle, $sql);
while ($list = mysqli_fetch_assoc($res)) {
$unit_of = $list['unit_of'];
?>
<option><?= $unit_of; ?></option>
<?php
}
?>
</select>
</div>
<input type="text" class="form-control-sm" id="rates" name="rates" >
<input type="text" class="form-control-sm" id="rates1" name="rates1" style="display:none">
<input type="text" class="form-control-sm" id="rates2" name="rates2" style="display:none">
每页、每小时、每天、每个月、每项、每项合同、其他
我希望更改多个选择、隐藏和显示输入类型编号,例如(name=“per_page”),例如(“每页输入率”),用于三种输入类型
预先感谢
发布于 2021-11-30 00:55:02
如果我理解正确的话,这里有两个问题:
如何将多个选择限制为最多三个选择?
实现这一点有多种方法,但我的建议是在表单提交之前验证此权利。如果使用的是表单验证库,请尝试在其中添加代码。如果没有,则可以添加一个自定义提交事件处理程序来验证所选内容。也许是这样:
$("form").on("submit", function(e) {
var selectionCount = $("#unit_of option:selected").length;
if (selectionCount > 3) {
e.preventDefault();
alert("You may only select up to 3 options.");
}
});
如何将占位符添加到多个选择中?
您可以在PHP代码添加其他选项之前添加占位符选项,如下所示:
<select class="form-control-sm selectpicker" multiple="multiple" id="unit_of"
name="unit_of[]" data-selected-text-format="count">
<option value="">Enter Rate Per Page</option>
<?php $sql = "select * from unit_of";
$res = mysqli_query($db_handle, $sql);
while ($list = mysqli_fetch_assoc($res)) {
$unit_of = $list['unit_of'];
?>
<option><?= $unit_of; ?></option>
<?php
}
?>
</select>
当然,使用这种方法,您需要添加额外的验证代码,以确保占位符选项不是所选选项之一。
https://stackoverflow.com/questions/70161751
复制相似问题