9 Comments

  1. 7/11/2010
    Reply

    and what about toggling more than one field by selecting only one checkbox?

  2. 7/11/2010
    Reply

    I find the solution, separating by ,
    But what with radio buttons, they do not reset when leaving (becose no click!)

  3. SuryaPrakash rao PC
    8/22/2010
    Reply

    This is One of the Good Site to learn Javascript Quickly

  4. cp444
    10/27/2010
    Reply

    This doesn’t work in FireFox. Is there a work around?

  5. cp444
    10/27/2010
    Reply

    Sorry, it must be that I am applying this to a div tag I did this to disable multiple input tags. Can I apply it to multiple areas of the form in the one action?

  6. 1/31/2011
    Reply

    A more elegant way to do the last line of toggle() would be instead of:
    updateToggle = checkbox.checked ? toggle.disabled=false : toggle.disabled=true;
    write:
    toggle.disabled= checkbox.checked;

    Then you could get rid of all the variables in the function:
    function toggle(checkboxId, toggleId) {
    document.getElementById(toggleId).disabled= document.getElementById(checkboxId).checked;
    }

    Or, you can get rid of the method altogether:

  7. 1/31/2011
    Reply

    Or, you can get rid of the method altogether:

    <input type=”checkbox” onclick=”this.form.disableMe.disabled=this.checked”/>

    <input type=”text” name=”disableMe”/>

  8. That was a really cool suggestion because it’s short, elegant and doesn’t require javascript code in the head, however it didn’t work for me…
    This did work for me:

    unfortunately it doesn’t toggle but at least it enables when the field is initially disabled (which is what I needed to do in my case)

    toggling would be nice though…

  9. 4/22/2015
    Reply

    Awesome! This was exactly what I was looking for! All the other examples I found used ajax or jquery, this is so much simpler. Thank you!

Leave a Reply