How can I make a link directly in the input field?

Using html (and maybe javascript =, but I wouldn’t want that), I would like to go from the link on one of my pages to the text box next to the button, focusing on this section. How can i do this?

+4
source share
4 answers

Do you want to focus on the text field when you click an item?

var d = document; d.getElementById("myLink").onclick = function() { d.getElementById("myTextInput").focus(); }; 

Demo

+1
source

Given an input that looks like this:

 <input id="myInput" type="text" value="" /> 

You can automatically translate your link into this text field by specifying the href attribute on the hash address:

 <a id="myLink" href="#myInput">Show me the textbox!</a> 

And a wire in javascript (with jQuery in this example) to focus on the text field when the link is clicked:

 $(document).ready(function() { $("#myLink").click(function(){ $("#myInput").focus(); }); }); 
+3
source

Assuming your text field has an id attribute, your link may point to its identifier with a hash, and onclick may focus it:

 <a href='#textboxid' onclick='document.getElementById("textboxid").focus();'>Click me</a> 

When the link is clicked, the page will be moved to the position of the text field using the hash #textboxid , and its focus() method is called to focus it.

+1
source
 <a href="#myinput">Input Link</a> <input type="text" value="Text Input" id="myinput" /> 

Using HTML, using the code above, you can only go to the input field.

+1
source

Source: https://habr.com/ru/post/1391148/


All Articles