M
Michel Bany
Hello everybody,
I am attaching an onclick event handler to a checkbox, using a <script> tag
<script>document.getElementById(id).onclick = ...</script>
and I have three questions.
1) In the handler I need to capture value of the "checked" property
My assumption is that I am getting the old value of this property, i.e.
before it has been toggled. And since I need the value that will result
from the click, I am coding this
// Compute the value that will result from the click
var checked = !document.getElementById(id).checked;
Is my assumption correct ?
2) I need to send the toggled value of the checked property to my
server using an AJAX so that I can modify some portions of
my document. After the AJAX is completed and document modified
I would expect that the checkbox view appears toggled, but it is not.
Any idea why ?
3) I tried to call the click() method in my onclick handler.
Is that legal ? Shouldn't this produce an infinite loop ?
Thanks,
Michel
I am attaching an onclick event handler to a checkbox, using a <script> tag
<script>document.getElementById(id).onclick = ...</script>
and I have three questions.
1) In the handler I need to capture value of the "checked" property
My assumption is that I am getting the old value of this property, i.e.
before it has been toggled. And since I need the value that will result
from the click, I am coding this
// Compute the value that will result from the click
var checked = !document.getElementById(id).checked;
Is my assumption correct ?
2) I need to send the toggled value of the checked property to my
server using an AJAX so that I can modify some portions of
my document. After the AJAX is completed and document modified
I would expect that the checkbox view appears toggled, but it is not.
Any idea why ?
3) I tried to call the click() method in my onclick handler.
Is that legal ? Shouldn't this produce an infinite loop ?
Thanks,
Michel