I cannoot figure out this seemingly simple problem. I have a checkbox and an onclick associated with it inside my JSP page. When i click the checkbox I need to check inside this onclick function whether it is checked or unchecked to know what action to take. However, it is always checked! I do not know why. Its almost like the click action completes and marks it checked before it gets to this function. However, if i do a simple HTML example page it works just fine and returns the correct value for .checked. I have tried removing "this" and just calling the checkbox by ID from onclick with the same results Here is the setup:
<label><input type="checkbox" onclick="selectEntireRange(this);"/> Select ALL Ranges</label>
Here is the JS:
function selectEntireRange(checkElement)
{
// if checked - remove check and display table rows normally
if(checkElement.checked)
{
//ALWAYS EXECUTES HERE!
checkElement.checked = false;
greyoutAllTableRows(false);
}
// if unchecked - mark 'checked' and grey out all table rows
else
{
checkElement.checked = true;
setAllCheckBoxes(false);
var selectedRangeField = document.getElementById('effRange');
selectedRangeField.value = '';
greyoutAllTableRows(true);
}
}
any help would be awesome! Thanks!
P.S. I cannot use jQuery for this!
onchangeevent insteadselectEntireRangeis called.