Skip to main content
Copy edited (e.g. ref. <http://en.wikipedia.org/wiki/HTML>).
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132

Though you have proposed a javascriptJavaScript solution for your problem (Displayingdisplaying a textbox when a checkbox is checked), this problem could be solved just by css. With this approach, your form works for users who have disabled javascriptJavaScript.

Assuming that you have the following htmlHTML:

<label for="show_textbox">Show Textbox</label>
<input id="show_textbox" type="checkbox" />
<input type="text" />

You can use the following cssCSS to achieve the desired functionality:

 #show_textbox:not(:checked) + input[type=text] {display:none;}

For other scenarios, you may think of appropriate css selectorsCSS selectors.

Here is a Fiddle to demonstrate this approach.

Though you have proposed a javascript solution for your problem (Displaying a textbox when a checkbox is checked), this problem could be solved just by css. With this approach, your form works for users who have disabled javascript.

Assuming that you have the following html:

<label for="show_textbox">Show Textbox</label>
<input id="show_textbox" type="checkbox" />
<input type="text" />

You can use the following css to achieve the desired functionality:

 #show_textbox:not(:checked) + input[type=text] {display:none;}

For other scenarios, you may think of appropriate css selectors.

Here is a Fiddle to demonstrate this approach.

Though you have proposed a JavaScript solution for your problem (displaying a textbox when a checkbox is checked), this problem could be solved just by css. With this approach, your form works for users who have disabled JavaScript.

Assuming that you have the following HTML:

<label for="show_textbox">Show Textbox</label>
<input id="show_textbox" type="checkbox" />
<input type="text" />

You can use the following CSS to achieve the desired functionality:

 #show_textbox:not(:checked) + input[type=text] {display:none;}

For other scenarios, you may think of appropriate CSS selectors.

Here is a Fiddle to demonstrate this approach.

added 1 character in body
Source Link
Ormoz
  • 3k
  • 10
  • 36
  • 50

Though you have proposed a javascript solution for your problem (Displaying a textbox when a checkbox is checked), this problem could be solved just by css. With this approach, your form works for users who have disabled javascript.

Assuming that you have the following html:

<label for="show_textbox">Show Textbox</label>
<input id="show_textbox" type="checkbox" />
<input type="text" />

You can use the following css to achieve the desired functionality:

 #show_textbox:not(:checked) + input[type=text] {display:none;}

For other scenarios, you may think of appropriate css selectors.

Here is a Fiddle to demonstrate this approach.

Though you have proposed a javascript solution for your problem (Displaying a textbox when a checkbox is checked), this problem could be solved just by css. With this approach, your form works for users who have disabled javascript.

Assuming that you have the following html:

<label for="show_textbox">Show Textbox</label>
<input id="show_textbox" type="checkbox" />
<input type="text" />

You can use the following css to achieve the desired functionality:

 #show_textbox:not(:checked) + input[type=text] {display:none;}

For other scenarios, you may think of appropriate css selectors.

Here is a Fiddle to demonstrate this approach

Though you have proposed a javascript solution for your problem (Displaying a textbox when a checkbox is checked), this problem could be solved just by css. With this approach, your form works for users who have disabled javascript.

Assuming that you have the following html:

<label for="show_textbox">Show Textbox</label>
<input id="show_textbox" type="checkbox" />
<input type="text" />

You can use the following css to achieve the desired functionality:

 #show_textbox:not(:checked) + input[type=text] {display:none;}

For other scenarios, you may think of appropriate css selectors.

Here is a Fiddle to demonstrate this approach.

added 15 characters in body
Source Link
Ormoz
  • 3k
  • 10
  • 36
  • 50

Though you have proposed a javascript solution for your problem (Displaying a textbox when a checkbox is checked), this problem could be solved just by css. thenWith this approach, your form works for users who have disabled javascript.

Assuming that you have the following html:

<label for="show_textbox">Show Textbox</label>
<input id="show_textbox" type="checkbox" />
<input type="text" />

You can use the following css to achieve the desired functionality:

 #show_textbox:not(:checked) + input[type=text] {display:none;}

For other scenarios, you may think of appropriate css selectors.

Here is a Fiddle to demonstrate this approach

Though you have proposed a javascript solution for your problem (Displaying a textbox when a checkbox is checked), this problem could be solved just by css. then your form works for users who have disabled javascript.

Assuming that you have the following html:

<label for="show_textbox">Show Textbox</label>
<input id="show_textbox" type="checkbox" />
<input type="text" />

You can use the following css to achieve the desired functionality:

 #show_textbox:not(:checked) + input[type=text] {display:none;}

For other scenarios, you may think of appropriate css selectors.

Here is a Fiddle to demonstrate this approach

Though you have proposed a javascript solution for your problem (Displaying a textbox when a checkbox is checked), this problem could be solved just by css. With this approach, your form works for users who have disabled javascript.

Assuming that you have the following html:

<label for="show_textbox">Show Textbox</label>
<input id="show_textbox" type="checkbox" />
<input type="text" />

You can use the following css to achieve the desired functionality:

 #show_textbox:not(:checked) + input[type=text] {display:none;}

For other scenarios, you may think of appropriate css selectors.

Here is a Fiddle to demonstrate this approach

Source Link
Ormoz
  • 3k
  • 10
  • 36
  • 50
Loading
Post Made Community Wiki by Ormoz