Javascript checkbox

In my HTML form page I have a textfield and a checkbox.
I want user not to be able to write inside the text field before he/she checks the checkbox (that means by default the checkbox will be unchecked and by default the textfield is not writeable). After user checks the checkbox, user can type in the textfield. How can we do it. ..pls help.

You guys are great!!
Hey..sorry actually I still have problem..actually in my page I have :
1 checkbox, 2 textfield and 1 selectfield.
When I choose one item in the selectfield, it populates the textfields (both) with some logic.

What I need is:
if checkbox is deselected:
"none of the textfields shall be writable", also even if we select any item in the selectfield, it will not populate any of the textfields!

if checkbox is selected:
both the textfield shall be writable and I should be able to populate the textfields by choosing items in the selectfield.

To clear things up, the difference between my code and adilkhan's code is that my code allows you to use the select box, but it won't write to the text fields unless checked while adilkhan's disables the select box along with the text fields. Not sure which one you're looking for.

Tooki, I come back to see how th equestion is going , I thought I ahd answered it now I find the has changed. This is my version, clicking the check box flips the disabled property for the field starting with all disabled. (ie !true=false and !false=true)

Thanks everyone!!Thanks a lot.Everyone's answer is acceptable to me.But there is one thing that :
after checking(selecting) the checkbox, if I type on the textfield(s) or choose an entry from the selectfield and then uncheck(deselect) the checkbox, the content of those textfield(s) remains and go through the form to the next page and I do not want that.

Is there any way that when the checkbox is deselected, the existing entries in the textfield(s) are set to null(blank)?

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Thanks much! It works but there is a problem too. After I submit (with some content in the textfields and the checkbox checked) and then if I come back to the previous page (current page that we are talking about), then the "checkbox remain checked but the textfields and the select field goes disabled!! If we uncheck the checkbox, the textfields and the select field becomes enabled, just the opposite of what was before the submit button was pressed"!!! Is there any way to make sure if the checkbox is selected certainly the textfields/selectfields are enables and if the checkbox is deselected the textfields/selectfields are disabled?

Here are the two files (the later one 2.html is the one that the form in 1.html calls:

Thanks Adilkhan!
I tried <Body onLoad="document.forms['myForm'].reset()">
Ok it keeps the checked checkbox checked when hit browser back button and it keeps unchecked checkbox unchecked,ok!
But how any textfield (that contains values before submitting the form) that are enabled before submit gets disabled after coming back using browser back button. How can I keep that same enabled status for the textfields (also the selectbox)?
thanks.
-tooki

Thanks.But I wrote the <body onLoad="default_vals()"> but I wrote below the default_vals() function but still the textfield C_31 andselect field select_31_1 always get disabled after I come back after the form submission,could you please help me with the syntax in the default_vals() function bolow:

Thanks.
But still this function default_vals() cannot enable the textfield C_31 and the select field select_31_1 (if they were enabled before the form submission).
I think this is because in the form the textfields/selectfield are craeated as 'disabled' by default:

No,actually it does not work for me. When we load the html page (1.html) fro the first time, I need everything disabled (V_31 disabled, select_31_1 disabled and R_31 unchecked).

Before I hit "submit" in 1.html, if R_31 is checked (i.e. V_31 enabled, select_31_1 enabled), I need to see R_31 checked, V_31 enabled and select_31_1 enabled after the "submit" in 1.html is pressed and I used the browser "Back" button to come back to "1.html".

Featured Post

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:
• Look-up is performed every time a variable is accessed.
• Variables are resolved backwards from most specific to least specific scope…

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …

The viewer will learn the basics of jQuery, including how to invoke it on a web page.
Reference your jQuery libraries: (CODE)
Include your new external js/jQuery file: (CODE)
Write your first lines of code to setup your site for jQuery.: (CODE)

The viewer will learn the basics of jQuery including how to code hide show and toggles.
Reference your jQuery libraries:
(CODE)
Include your new external js/jQuery file:
(CODE)
Write your first lines of code to setup your site for jQuery…