Forum Moderators: open
<input type='checkbox' name='thechk' onClick='document.form.advtxt[0].disabled=false;'><input type='text' name='thetxt' disabled=true>
<input type='checkbox' name='thechk' onClick='document.form.advtxt[1].disabled=false;'><input type='text' name='thetxt' disabled=true>
<input type='checkbox' name='thechk' onClick='document.form.advtxt[2].disabled=false;'><input type='text' name='thetxt' disabled=true>
=============
I need the element referentials to be the same. ie: onClick='document.form.thetxt[this.index].disabled=false;'
(or however I can manage to get that to work.)
I need to reference which element of the thechk I'm on and tell the same element of the thetxt to enable, rather than going through the literal 200 of them I have and referencing each individually. It will be a major headache when I have to change the third of 200 and everything after that to it's next element up.
I even have some versions that have javascript functions to do the same thing, but the issue seems to be having it figure out which of the thechk index elements it is looking at.
I've tried doing arrays and javascript writeLn to make this happen, but there is long paragraphs of data in between and it just isn't feasible to have them in arrays, so I need to figure out how to make this work, but no combination I've found or tried so far has made it happen and it just seems like something that shouldn't be so difficult to figure out. I'm stumped.
<script type="text/javascript">
window.onload = function () {
document.forms["someForm"].reset();
var i = 0,group = document.forms.someForm.thechk;
while(group[i]) {
group[i].onclick = function (I) {
return function () {
var el = this.form.thetxt[I];
if (el) {
el.disabled = !this.checked;
}
};
}(i);
i++;
}
};
</script><form action="" name="someForm">
<p>
<input type="checkbox" name="thechk"><input type="text" name="thetxt" disabled="disabled"><br>
<input type="checkbox" name="thechk"><input type="text" name="thetxt" disabled="disabled"><br>
<input type="checkbox" name="thechk"><input type="text" name="thetxt" disabled="disabled">
</p>
</form>
eg
<span><input type='checkbox' name='thechk' onClick='document.form.advtxt[1].disabled=false;'><input type='text' name='thetxt' disabled=true></span>
then the pair of inputs can be had by
var els = this.parentNode.getElementsByTagName('input');
els[0] is the checkbox and els[1] the corresponding text box
counter = 0;
while(someCondition) {
document.writeln("<input type='checkbox' name='thechk" + counter + "' onClick='document.form.thetxt" + counter + ".disabled=false;'><input type='text' name='thetxt" + counter + "' disabled='true'>");
counter++;
}