So I was working on a web application that use HTML check box, the check box was losing its value during postback, to solve this I used the OnBlure Event
<input onBlur=’updateValue(this)’ id=”CHECKBOX1″ type=checkbox checked=”CHECKED”/>
This is the JavaScript function UpdateValue:
function updateValue(inputField)
{
if (typeof inputField == “string”)
{
inputField = document.getElementById(inputField);
}
if (inputField.type == “select-one”)
{
for (var i=0; i<inputField.options.length; i++)
{
if (i == inputField.selectedIndex)
{
inputField.options[inputField.selectedIndex].setAttribute(“selected”,“selected”);
}
}
} else if (inputField.type == “text”) {
inputField.setAttribute(“value”,inputField.value);
} else if (inputField.type == “textarea”) {
inputField.setAttribute(“value”,inputField.value);
} else if ((inputField.type == “checkbox”) || (inputField.type == “radio”))
{
if (inputField.checked)
{
inputField.setAttribute(“checked”,“checked”);
}
else
{
inputField.removeAttribute(“checked”);
}
}
}






