I’m having a aspx form with few mandatory fields. I’ve applied the same style for all those fields say txtbxrequired. I want to color all those skipped mandatory fields to yellow. How to achieve that. Below is the code I’m using but it colors even the filled fields:
if ($(".txtbxrequired").val() == "") {
$(".txtbxrequired").css("background-color", "yellow");
}
http://jsfiddle.net/zerkms/FAs6W/
Your code doesn’t work because you explicitly set yellow color to all elements that has class
txtbxrequired.What my code does is – selects all the elements with
txtbxrequiredclass, then filters only ones, that doesn’t have any value, and sets the background color for them