How to get default value from checkbox element?
Below is my code:
<INPUT TYPE="checkbox" NAME="cb" value="1">
After submitting the form, I get cb==1if the item is cbchecked,
I want to receive cb==0if the item is cbnot installed. How to implement it?
BTW: it is not possible to change the receipt page, for example:
if(cb==null)cb=0;// no no no..
I want to implement it on a web interface.
I tried like this:
<INPUT TYPE="hidden" NAME="cb" value="0"> <!--add this line-->
<INPUT TYPE="checkbox" NAME="cb" value="1">
If cbnot checked, it can override <INPUT TYPE="hidden" NAME="cb" value="0">else, I can get cb==0.
but I think this solution is not very good.
any idea? thanks ~ :)
Thanks wowo_999 for the comment:
" checkbox , , . , , cb 2x , ". - wowo_999
cb "0", , null, : "java.sql.SQLException: " cb " " null ", cb == 0, null. ( cb sql, cb "0".)
, , javascript . , jQuery:
$("input[type=checkbox]").change(function() {
$(this).attr("value", $(this).attr("checked") ? 1 : 0);
});
, script :
$(function() {
function updateCheckbox() {
$(this).attr("value", $(this).attr("checked") ? 1 : 0);
}
// Run whenever checkbox is ticked or unticked
$("input[type=checkbox]").change(updateCheckbox);
// Run on page load
updateCheckbox();
});
HTML, - value:
<input type="checkbox" name="cb" />
:
<input type="checkbox" name="cb" checked />