multi select with validation for different type value validation
by Prasanth AR
HTML
<link rel="stylesheet" href="http://www.erichynds.com/examples/jquery-ui-multiselect-widget/jquery.multiselect.css">
<link rel="stylesheet" href="http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/assets/style.css">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/ui-lightness/jquery-ui.css">
<script src="http://www.erichynds.com/examples/jquery-ui-multiselect-widget/src/jquery.multiselect.js"></script>
<select id="mltyslct" multiple="multiple" size="5">
<option value="A">AA</option>
<option value="B">AB</option>
<option value="C">AC</option>
<option value="1">11</option>
<option value="2">12</option>
<option value="3">13</option>
</select>
JavaScript
$( document ).ready(function() {
$("select").multiselect();
});
var strAppnd='';
var selectValue='';
var flag=true;
$( "#mltyslct" ).change(function() {
var foo = [];
$('#mltyslct :selected').each(function(i, selected){
foo[i] = $(selected).val();
});
for (var i = 0; i < foo.length; ++i) {
selectValue = foo[i].substring(0, 1);
}
if(selectValue=="A"){
alert('alphabet');
strAppnd=strAppnd+'A';
selectValue=''
flag=false;
}
else if(selectValue=="1"){
alert('number');
if(flag==false){
strAppnd=strAppnd+'1';
}
selectValue=''
}
console.log('val of appndStrng:'+strAppnd.substring(0, 2));
if(strAppnd.substring(0, 2)=='A1'|| strAppnd.substring(0, 2)=='1A'){
for (var i = 0; i < foo.length; i++) {
$("#mltyslct option[value='"+foo[i]+"']").prop("selected", false);
console.log('inside Booom:'+foo[i]);
}
}
});