I am writing validation on a custom dropdown DD1 and DD2, but when it checks for DD1, and return false, it doesn’t check for DD2. Can you please suggest me?
In the below script, i am calling Validatechecked function where it checks whether the dropdown has selected values, it works for only one dropdown. How to make it work for more than 2 dropdowns??
<script type="text/javascript" language="javascript">
function Validatechecked(val) {
var selectedItems = "";
$('[id*='+val+']'+" "+ "input:checked").each(function () {
if (selectedItems == "") {
selectedItems = "Selected Items:\r\n\r\n";
}
selectedItems += $(this).next().html() + "\r\n";
});
if (selectedItems == "") {
selectedItems = "";
return false;
}
else {
selectedItems = "";
return true;
}
}
$(document).ready(function () {
$('[id*="InsertNSTBtn"]').click(function () {
if (!Validatechecked("DD1")) {
$('#<%=valid1.ClientID%>').html("*");
return false;
}
if (!Validatechecked("DD2")) {
$('#<%=Valid1.ClientID%>').html("*");
return false;
}
});
});
Instead of returning false right away, set a Boolean variable to false and return that: