I am trying to change the value of a hidden input field, depending on the value of the checkbox. I am not very good at Javascript, but this is what I still have.
<input type="hidden" value="" id="delterms" name="O_" />
<input type="checkbox" id="checkbox" onchange="terms()" />
<script type="text/javascript">
var checked = document.getElementById('checkbox').checked;
function terms() {
if (checked==false)
{
document.getElementById('delterms').value=''
}
else
{
document.getElementById('delterms').value='Accepted'
}
}
</script>
I got it to work, but only on the first click, anyway, to set the value depending on the status of the checkbox? I suspect there is a much simpler way, and I will no doubt complicate the problem.
source
share