1

I want to create a webpage which contains an input box, and a button.

The Input-Box is for a Barcode-Scanner, a number which has been scanned, should be written to that input box., the problem is now, when i enter the page, the input field has no cursor in it, i have to click in it first.

Is there a way to set a cursor by default in the box? like open the page and be ready to scan?

1 Answer 1

3

If you're using html5 you can use the autofocus attribute.

<input type="text" autofocus>

Or you can set the focus on load

window.onload = function(){
 document.getElementById('idOfTextbox').focus();
}
Sign up to request clarification or add additional context in comments.

1 Comment

@sgtBear anywhere inside <script> tag

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.