admin管理员组文章数量:1392073
In my web application we have used the twitter-bootstrap theme. I have to do client side validation for one form in my application. The form includes text fields,checkboxs and multiselect dropdowns. I can validate textfield and checkboxes but i cant validate the dropdown.
<select id="users" name="username[]" class="chzn-select span2" multiple="multiple">
<option value="sdfsd">sdfsdfs</option>
....
</select>
But during runtime the select tag is hide and they generate <li>
tags.
I cant use document.getElementByID();
Please provide me the best way to do the validation.
In my web application we have used the twitter-bootstrap theme. I have to do client side validation for one form in my application. The form includes text fields,checkboxs and multiselect dropdowns. I can validate textfield and checkboxes but i cant validate the dropdown.
<select id="users" name="username[]" class="chzn-select span2" multiple="multiple">
<option value="sdfsd">sdfsdfs</option>
....
</select>
But during runtime the select tag is hide and they generate <li>
tags.
I cant use document.getElementByID();
Please provide me the best way to do the validation.
Share Improve this question edited Dec 5, 2013 at 16:09 Sparky 98.8k26 gold badges202 silver badges290 bronze badges asked Dec 5, 2013 at 10:11 user3069614user3069614 632 silver badges5 bronze badges 1- Please do not use jquery-validate tag when the question has noting to do with this plugin. Edited. Thanks. – Sparky Commented Dec 5, 2013 at 16:11
2 Answers
Reset to default 4Try this
HTML
<form action="#">
<select id="users" name="username[]" class="chzn-select span2" multiple="multiple">
<option value=""></option>
<option value="sdfsd">sdfsdfs</option>
....
</select>
<input type="submit" id="add_btn">
</form>
Script
$('#add_btn').on('click', function(e) {
if($('#users').val() == null && $('#users_chosen').is(':visible')) {
alert('You must choose division');
}
});
DEMO
OR
$(function(){
$('form').submit(function(){
var options = $('#users > option:selected');
if(options.length == 0){
alert('no value selected');
return false;
}
});
});
DEMO
//You can use Js for this
var ptype=document.getElementById('username').options[document.getElementById('username').selectIndex].value;
if(ptype=""){
document.getElementById('username').style.display='none';
alert('Please select field');
document.getElementById('username').focus();
return false;
}
本文标签: javascriptHTMLJSBOOTSTRAPvalidate the multiselect dropdownStack Overflow
版权声明:本文标题:javascript - HTML:JS:BOOTSTRAP ; validate the multiselect dropdown - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744762481a2623833.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论