I have a select box that uses jcf plugin. As documenation says we have to refresh method to change the value but it is not changing. Below here is what i have tried?
$(function() { jcf.replaceAll(); }); function changeValue() { $("#mgloc_npgpo").val('1') jcf.getInstance($("#mgloc_npgpo")).refresh() }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jcf/1.2.3/js/jcf.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jcf/1.2.3/js/jcf.select.js"></script> <div class="select-holder"><label>Selection</label> <div class="select-wrap"><input type="hidden" id="mgloc_340b" value=""/> <div class="select-wrap"><input type="hidden" id="mgloc_340b" value=""/> <select id="mgloc_npgpo" multiple="multiple" data-jcf="{"wrapNative": false, "wrapNativeOnMobile": false, "useCustomScroll": false, "multipleCompactStyle": true}" class="jcf-hidden"> <option value="" selected="selected">Select Non-Primary</option> <option value="1">value 1</option> <option value="2">value 2</option> </select> <div class="errorMsg hide"> </div> </div> <div class="errorMsg hide"> </div> </div> <button style="margin-top: 100px;" onClick="changeValue()">change value</button> </div>
You have a typo
Your id name mgloc_npgpo
not mgloc_ngpo
In your js code you have used mgloc_ngpo
at every place. which should be mgloc_npgpo
$(function() { jcf.replaceAll(); }); function changeValue() { $("#mgloc_npgpo").val('1') jcf.getInstance($("#mgloc_npgpo")).refresh() }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jcf/1.2.3/js/jcf.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jcf/1.2.3/js/jcf.select.js"></script> <div class="select-holder"><label>Selection</label> <div class="select-wrap"><input type="hidden" id="mgloc_340b" value=""/> <select jcf id="mgloc_npgpo" data-jcf="{"wrapNative": false, "wrapNativeOnMobile": false, "useCustomScroll": false, "multipleCompactStyle": true}" class="jcf-hidden"> <option value="" selected="selected">Select Non-Primary</option> <option value="1" >value1</option> <option value="2" >value2</option> </select> <div class="errorMsg hide"> </div> </div> <button onClick="changeValue()">change value</button> </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.