How to put the cursor automatically to the specified input field
It – Hardware & Software | Tyler Shymske | 10 viewsIn the page which such as message transmission form has inputting a some letter to the access person and questionnaire form, when from first cursor has entered into the first input column, it is convenient. Using the mouse, because you can exclude the time which specially clicks the input column is.
– When from first cursor has entered into the first input column, convenience |
When JavaScript is used, it can actualize the method from first of trying to insert cursor in the input column of specification, easily. JavaScript which you describe passed is 1 lines.
To insert cursor in the designated input column
We introduce the contents which you describe first just simply. Description procedure is as follows.
- Id is allocated to the input column
- The script 1 lines is written
[STEP.1] Id is allocated to the input column
First, being automatic, cursor in the input column which we would like to insert, using id attribute, it adds ID name.For example, it makes like below. (* Here, it has made the ID name, “firstinput”.)
<input type= ” text ” id= ” firstinput ” >
[STEP.2] The script 1 lines is written
That next, focusing is given to the element which had some time ago ID name, JavaScript is described.
document.getElementById(‘ firstinput ‘).focus();
to describe the, this is the only only.
in this, firstinput thatIDyou can put the cursor to the input automatically added to the name.
if the buttons and check boxes instead of the input field, will be selected.
it is difficult to understand the above description is only to describe the copper or concrete, in the following pages take advantage of a more concrete case (source) we will introduce them with the.
take advantage of a concrete case (source) to >>
concrete source put the cursor to the specified input
HTMLpart:
first, such as:HTMLsuppose you have a. is the input field3there are three. (inputby elements1the run-line input2bract, textareais a multi-line input field by elements1one)
your name: <input type=”text” size=”30″ name=”name”><br>
e-mail: <input type=”text” size=”30″ name=”mail”><br>
comment: <textarea name=”comment” cols=”30″ rows=”5″></textarea><br>
of this, the first input field (here your name column) consider the case where you want to place the cursor automatically. there, your name are making a fieldinputelementsidadd the attribute, written as follows:.
your name: <input type=”text” size=”30″ name=”name” id=” firstinput ” ><br>
e-mail: <input type=”text” size=”30″ name=”mail”><br>
comment: <textarea name=”comment” cols=”30″ rows=”5″></textarea><br>
JavaScriptpart (type1) :
to put the cursor automatically to the specified input fieldJavaScriptis, of the pagebodyin the tagonloadbe described by using the attributes as follows:.
<body onload=”document.getElementById(‘ firstinput ‘).focus();” >
bodyelement ofonloadscript was written as the value of the attribute, will be executed after the page load is complete. that is, has been completed at the same time as the page read, will be the cursor enters the specified input field.
JavaScriptpart (type2) :
in our case the above, after page load for the script to be executed, in such a large page takes a long time to complete reading the entire page, it can take even longer until the cursor is automatically. in such a case, entry field (input form) ofHTMLimmediately after describing the, you can also use to describe how to put the scripts as follows:.
<script type=”text/javascript”>
document.getElementById(‘ firstinput ‘).focus();
</script>
if you write as above, without waiting for the completion of the entire page read, the cursor will immediately enter.
note on the description:
this type2 if you write in the way of the, make the specified input fieldinputthan the element after please describe the script. targetinputwhen they write a script before the above elements, specifiedIDthere is no i get errors that.
conclusion
this time, we show you how to put the cursor automatically to a specific input field. survey form, such as forms and send a message, please use such as pages that need to get some sort of character who enter the access.
Incoming search terms:
- Automatically Putting the Cursor in a Field (1)
- how to put * in input box access (1)
Additional items from "It – Hardware & Software"
- Lenovo ThinkPad X60
- BOSE SoundDock review! take advantage of more! iPod mini
- pcDtrying to take advantage of the drive
- PHP5installing and configuring
- 10less than ten thousand yen good find the! KDL-16M1
- to reduce the size of the image material3one+αmethod of let’s reduce the image
- 2the title of the line1line fit to2ways
- world firstSideShowequipped withASUS W5Fe
- with easy installation, good sound easy to enjoy YHT-S401
- Office Spesialist Word, ExcelofExpertfull marks! her senior2reason for the perfect score for both subjects