How Do I Use Javascript To Change Value Of A Hidden Input Depending On Status Of A Checkbox?
The idea is that the anonymous function gets run every time the user clicks the checkbox, which sets the value of the hidden field to either "Accepted" or the empty string, depending on whether or not the box is checked.
This jsFiddle shows a working example.
Solution 2:
Move the variable assignment into the function, thus:
functionterms() {
var checked = document.getElementById('checkbox').checked;
if (checked==false)
Solution 3:
Fixed in a fiddle - use the Event of clicking.
Solution 4:
Because checkboxes are not submitted in a form.submit() when they are unchecked I use a hidden field that gets updated when the checkbox is clicked on.
<input type="hidden"id="chbx" value="" name="0_">
<input type="checkbox"id="__chbx"
onclick="document.getElementById('chbx').value =
document.getElementById('__chbx').checked;"/>
(I have omitted the jsp-code that adds the checked
property to the checkbox-input if it was already checked when rendering the page.)
Solution 5:
Your variable checked
is set only once, so it always equals to the inital value. Move it inside your function terms()
.
Post a Comment for "How Do I Use Javascript To Change Value Of A Hidden Input Depending On Status Of A Checkbox?"