In javascript, how can I refer to this.form.checkbox [5] .checked?
I have a series of checkboxes and type = "text" input areas where I need to set the checkbox state to true when the value in the text area changes. Simple enough. I did it successfully:
<input name="fixed" type="checkbox">
<input name="stuff" type="text" onchange="this.form.fixed.checked=true">
Which works great. You have to edit the field and then click it, but this is ok for my needs:
... but when I switch to this:
<input name="fixed[0]" type="checkbox">
<input name="stuff" type="text" onchange="this.form.fixed[0].checked=true">
<input name="fixed[1]" type="checkbox">
<input name="stuff" type="text" onchange="this.form.fixed[1].checked=true">
I don't change my checkboxes when editing:
My only know-how in javascript comes from this kind of thing, I'm afraid. Does anyone have better information on this than Oracle Google on The Mountain has in store?
thank...
source to share
Perhaps you are mixing some shadow methods in HTML and when you do it in javascript they break.
So this.form.fixed [1] in javascript actually says "The second element in the array this.form.fixed. So I think that's the problem. Try naming the elements fixed0 and fixed1 and see if that works."
Edit . You can also use parenthesis notation as shown by Peter, which should solve the problem without editing the input names.
source to share
Make life easier for yourself.
Create a unique identifier for the elements you are trying to link to, and reference them from the elements you link events to:
<input name="fixed[0]" type="checkbox" id="fixed_0">
<input name="stuff" type="text" onchange="document.getElementById('fixed_0').checked=true">
<input name="fixed[1]" type="checkbox" id="fixed_1">
<input name="stuff" type="text" onchange="document.getElementById('fixed_1').checked=true">
source to share