Search code examples
checkboxonload

Form with checkboxes and hidden values on reload page


I don't know if this makes any sense but I have a form with checkboxes and once the user clicks on the box it will show a hidden message. But once I reload the browser, the checkbox is still checked off but the hidden message is no longer there.

<input type="checkbox" id="CB6" name="" value=""> 

<table name="hidden" id="hidden" style="display:none;">
<tr>
<td>It works</td>
</tr>
</table>

<script type="text/javascript" language="JavaScript">
$(document).ready(function() {
$('#CB4').click(function() {
if($(this).is(':checked')) {
$('#hiddenRAcost').show();
} else {
$('#hiddenRAcost').hide();
}
});
});
</script>

Is there like an onload function or something when a user reloads the page, it can run that script?

Thanks


Solution

  • <body onload="myFunc()">
    ...
    </body>
    

    Whenever the body loads (or page), myFunc() will run, so you can use this to check.