简体   繁体   中英

after checkbox checked, redirection to a textbox

Is it possible that when I check a checkbox it redirects me directly to a textbox ? Like if I did a TAB when I check it.

And if possible only with HTML and CSS

You can't do it with just HTML & CSS

but here is a solution using javascript:

window.onload = function() {
  var checkbox = document.getElementById("agree"),
      textbox = document.getElementById("textbox");

  checkbox.onclick = function() {
    if(this.checked) {
      textbox.focus();
    }
  };
};

demo

Maybe the minimal implementation would be:

<form name="f1">
    <input id="in1" name="in1" type="checkbox" onClick="if(this.checked) document.f1.in2.focus()" /> Check option <br/>
    <input id="in2" name="in2" type="text" />
</form>

Fiddle demo

The simpliest way is to use TabIndex attribut in the input element

<input type="checkbox" Tabindex="1"> </input>
<br>
<br>
<input type="text" Tabindex="2"> </input>

I hope this might help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM