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;
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744762482a4592253.html
评论列表(0条)