Activate input field from input

I want to activate the input field by checking the box.

I have a basic form:

<ul>
 <li>
  <label id="form-title" for="name3">Specifics:</label>
 <li>   
  <textarea id="name3" name="name3" >

  </textarea>
 </li>

</ul>

You click on "Specifics" and activate this field. Can this be done using an input tag instead of a tag tag?

Example:

<ul>
 <li>   
  <input type="checkbox" for="name2">Other...</input>
  <input id="name2" name="name2" />
 </li>
</ul>

jsfiddle full work so far: http://jsfiddle.net/Sederu/gaZDW/

+5
source share
4 answers

To do this, you will need a little EMCAScript.

<label for="name3">
  <input type="checkbox" id="name3activaitor" onclick="if(this.checked){ document.getElementById('name3').focus();}" />
  Other...
</label>
<input type="text" id="name3" name="name3" />

The built-in handler sees whether the checkbox has been checked, and if it is, focuses text input. I put a checkbox in a label just to symbolically group it with a label, since it performs the same function, but you can put the flag anywhere.

/ , , :

        <input type="checkbox" onclick="var input = document.getElementById('name2'); if(this.checked){ input.disabled = false; input.focus();}else{input.disabled=true;}" />Other...
        <input id="name2" name="name2" disabled="disabled"/>
+13

. javascript :

<input type="checkbox" id="checkbox1" onclick="if (this.checked){ document.getElementById('textarea1').removeAttribute('disabled');}" />
<textarea id="textarea1" name="textarea1" disabled></textarea>
+4

You can do it with a little javascript,

HTML

<ul>
 <li>   
  <input type="checkbox" id="checker" for="name2">Other...</input>
  <input id="name2" name="name2" />
 </li>
</ul>

JAVASCRIPT

document.getElementById('checker').onchange = function() {
 if(this.checked==true){
  document.getElementById("name2").disabled=false;
  document.getElementById("name2").focus();
 }
 else{
  document.getElementById("name2").disabled=true;
 }
};

Hope this helps

+1
source

All other answers work, but it's simple:

<input type="checkbox" id="checkbox"><label class="checkbox" for="checkbox"> Remember Me!

Explanation:

  • <input defines a tag call.
  • type="checkbox"defining a flag.
  • id="checkbox"> identifies it as a "flag".
  • <label class="checkbox"by classifying it as a “checkbox”.
  • for="checkbox"> calls this checkbox
  • Remember Me! What he says next to the flag.
-1
source

All Articles