admin管理员组文章数量:1336645
I Have a Multiple selection select box. I need it to be validated using javascript, so that it should prompt to select atleast one value.
Below is the multiple select box I Have.
<select name="usrgrp[]" multiple="multiple" size="3">
<option value="11">abc</option>
<option value="12">def</option>
<option value="13">ghi</option>
</select>
Please help me to write the validation javascript for this select box.
I Have a Multiple selection select box. I need it to be validated using javascript, so that it should prompt to select atleast one value.
Below is the multiple select box I Have.
<select name="usrgrp[]" multiple="multiple" size="3">
<option value="11">abc</option>
<option value="12">def</option>
<option value="13">ghi</option>
</select>
Please help me to write the validation javascript for this select box.
Share Improve this question asked Jan 25, 2011 at 14:03 OM The EternityOM The Eternity 16.2k44 gold badges125 silver badges187 bronze badges3 Answers
Reset to default 3if (referenceToForm.elements["usrgrp[]"].selectedIndex == -1) {
alert("Please select an item.");
}
the easiest way is use ! :
if (!$('select').val())
{
//fail
}
I would start with the Validation docs. If you find the need to validate more than just that field (perhaps you're building a form?), then using the Validation pluggin will help you much more than hacking together individual rules.
Give it a shot, it's well written and contains many examples.
本文标签: Javascript quotMULTIPLE Selectionquot Select box validationStack Overflow
版权声明:本文标题:Javascript "MULTIPLE Selection" Select box validation? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742245993a2439527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论