admin管理员组文章数量:1405350
I want to use bs input tag for a select box in which options are ing from the database. When I type some letter or word in the input it needs to filter from options... I need to select multiple options with remove.
please help me
My dropdown code
<select class="form-control required" name="cpt_codes" id="cpt_codes">
<?php
for ($i=0; $i < count($cpt); $i++) {
if($cpt[$i]['cpt_code']==$result['patient'][0]['cpt_code']){ ?>
<option value="<?php echo $cpt[$i]['cpt_code'];?>" selected>
<?php echo $cpt[$i]['cpt_code'];?>
</option>
<?php } else{ ?>
<option value="<?php echo $cpt[$i]['cpt_code'];?>">
<?php echo $cpt[$i]['cpt_code'];?>
</option>
<?php } ?>
<?php }?>
</select>
I want to use bs input tag for a select box in which options are ing from the database. When I type some letter or word in the input it needs to filter from options... I need to select multiple options with remove.
please help me
My dropdown code
<select class="form-control required" name="cpt_codes" id="cpt_codes">
<?php
for ($i=0; $i < count($cpt); $i++) {
if($cpt[$i]['cpt_code']==$result['patient'][0]['cpt_code']){ ?>
<option value="<?php echo $cpt[$i]['cpt_code'];?>" selected>
<?php echo $cpt[$i]['cpt_code'];?>
</option>
<?php } else{ ?>
<option value="<?php echo $cpt[$i]['cpt_code'];?>">
<?php echo $cpt[$i]['cpt_code'];?>
</option>
<?php } ?>
<?php }?>
</select>
Share
Improve this question
edited Jul 25, 2018 at 9:42
Zakaria Acharki
67.5k15 gold badges78 silver badges106 bronze badges
asked Jul 25, 2018 at 9:40
MadhuriMadhuri
291 gold badge1 silver badge5 bronze badges
2
- 1 Have you try jquery select2 plugin ever ? – er-sho Commented Jul 25, 2018 at 10:23
- no,I have not tried jquery plugin – Madhuri Commented Jul 25, 2018 at 10:24
2 Answers
Reset to default 3This is a sample of jquery select2 plugin that demonstrate that you can select tag from data or type any other that not exist in data.
If you want data to be es from any url then you have to use ajax call inside select2 option.
You can refer more sample of select2 from here
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="https://cdnjs.cloudflare./ajax/libs/select2/4.0.5/css/select2.min.css" />
</head>
<body>
<select class="form-control select2" multiple="multiple" style="width: 100%;"></select>
<script src="https://code.jquery./jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://code.jquery./ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/select2/4.0.5/js/select2.full.min.js"></script>
<script>
$('.select2').select2({
data: ["Piano", "Flute", "Guitar", "Drums", "Photography"],
tags: true,
maximumSelectionLength: 10,
tokenSeparators: [',', ' '],
placeholder: "Select or type keywords",
//minimumInputLength: 1,
//ajax: {
// url: "you url to data",
// dataType: 'json',
// quietMillis: 250,
// data: function (term, page) {
// return {
// q: term, // search term
// };
// },
// results: function (data, page) {
// return { results: data.items };
// },
// cache: true
// }
});
</script>
</body>
</html>
{<!-- Created by Oc -->}
<select class="form-control required" name="cpt_codes">
<?php
for ($i=0; < count($cpt); $i++) {
if($cpt[$i]['cpt_code']==$result['patient'][0]['cpt_code']){ ?>
<option value="<?php echo $cpt[$i]['cpt_code'];?>" selected>
<?php echo $cpt[$i]['cpt_code'];?>
</option>
<?php } else ?>
</option>
<?php } ?>
<?php }?>
</select>
本文标签: javascriptHow to use bootstrap tag input for selectStack Overflow
版权声明:本文标题:javascript - How to use bootstrap tag input for select - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744897206a2631135.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论