Q:

Checkbox enabling inactive fields

I was just wondering if it is possible to enable an inactive field by checking a checkbox by using javascript? For example the following the text field is initially disabled but if you check the checkbox the text field enables and allows you to enter a value
<input type="checkbox" name="enable" id="enable">

<input type="text" id="name" name="name">

I have done some searching but I cant seem to find something that works well and I am fairly new to javascript so any help or a nudge in the right direction would be great.

A:

Try this
window.onload=function(){
    document.getElementById('enable').onchange=function(){
        var txt = document.getElementById('name');
        txt.disabled = !this.checked;
    };
};

DEMO1 and DEMO 2.

