we can also use a common function that binds to different event associated with different elements and we only pass id and access the function by identifying id in function argument like this
function ValidateForAllValue(id )
{
var str=""
$("select#"+id+" option:selected").each(function ( )
{
if($(this).val() =="Defined" )
{
str=str+$(this).val();
}
if(str=="Defined" && $(this).val() != "Defined")
{
alert("Invalid selection: option 'All' can not be selected with any other option");
$(".AllClass").val([])
return false;
}
if ($(this).val() == "None")
{
$(".AllClass").val([]);
alert("Select some valid option");
}
});
};
Here this function displays alert for the element if user select "All" along with other option.Therefore we can call this function for any select list by passing on onclick attribute like this:
<select onclick="ValidateForAllValue(this.id)">
No comments:
Post a Comment