Cannot get this to work. First time using variables passed into functions. Unchecking radio button should disable form field and vice versa. lineid variable distinguishes this radio/text input pair from 10 others.
My code:
<script type="text/javascript">
function disablefield(lineid){
if (document.getElementById(lineid).checked == true){
document.dupedit.lineid.disabled = false;
} else {
document.dupedit.lineid.disabled = true;
}
}
</script>
Subset of my HTML.
You need to pass a string into your
disablefieldfunction, so put the value in quotes when you pass it in. Something like:<input onclick="disablefield('2671997')" />This is because
document.getElementByIdexpects a string, not an integer.Secondly, to enable/disable the field, you need to use
disabled = true;rather than= 'disabled'.document.dupedit.lineidis looking a for a field with name “lineid”, which doesn’t exist in your form. I would suggest giving the field anidand usingdocument.getElementByIdagain instead.If you want to continue using the
nameattribute, you will have to usedocument.getElementsByNameinstead. This returns an array of matching elements (since multiple elements can share the same name), but if in your code you know that the element in question is the only one with that name, you can do this:You can see a working version (I think this is how you wanted it anyway) here. And here is a version using
getElementsByName.