I’d like to be able to offload setStatus() to take a few arguments – but right now I can’t even get the hardcoded selectors to work. How do i offload the setStatus() function correctly?
HTML
<div id="first:test"> <span class="statusFlag"></span>
<br/>
<input type="checkbox" value="Stuff">Box 1</input>
<input type="checkbox" value="Stuff">Box 2</input>
<input type="checkbox" value="Stuff">Box 3</input>
</div>
<div id="second:test"> <span class="statusFlag"></span>
<br/>
<input type="checkbox" value="Stuff">Box 1</input>
<input type="checkbox" value="Stuff">Box 2</input>
<input type="checkbox" value="Stuff">Box 3</input>
</div>
<div id="noTest">
<input type="checkbox" value="stuff">No Validate</input>
</div>
Jquery
$('[id$=test] input:checkbox').change(function () {
if ($(this).parent().children('input:checkbox').filter(':checked').length > 0) {
setStatus(this);
} else {
$(this).closest('[id$=test]').find('.statusFlag').css('color', 'red').text('Incomplete');
}
});
function setStatus(oldthis){
alert(oldthis);
$(oldthis).closest('[id$=test]').find('statusFlag').css('color', 'green').text('Complete');
}
The idea is to pass selectors dynamically and have text set for each div section…so eventually something like:
setStatus(this, '[id$=test]', 'red', 'Incomplete');
Fiddle here
http://jsfiddle.net/pMAXs/
You are not finding a class in the second selector.
“statusFlag” -> “.statusFlag”
Assuming I understood your end goal to be correct, see: http://jsfiddle.net/pMAXs/3/