I want to make a checkbox to control two textfield

The checkbox default checked

and two textfield default disabled

When user uncheck the checkbox , These two textfield do not disabled.

How can I write the script?

Here is something that i came up with, but its untested and its just to get you going. I would suggest using jQuery because the code would be much more simple with this problem that you are having.

<script type="text/javascript">
function toggle(){
    if (document.getElementById("input1").disabled == false){
        document.getElementById("input1").disabled = true;
        document.getElementById("input2").disabled = true;
        return
    }
    if (document.getElementById("input1").disabled == true){
        document.getElementById("input1").disabled = false;
        document.getElementById("input2").disabled = false;
        return
    }

} 
</script>

Then just call it using the jquery onload function.

HTML

<input type="checkbox" id="check1" onclick="toggle()" />
<input type="text" id="input1">
<input type="text" id="input2">

hope this helps

Man my javascript never posted.

function toggle() {
    if(document.getElementById("check1").checked){
        document.getElementById("input1").disabled = true;
        document.getElementById("input2").disabled = true;
    } else {
        document.getElementById("input1").disabled = false;
        document.getElementById("input2").disabled = false;
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.