2

I would like the cursor to be automatically placed in a textbox when my page loads. However, I do not want the page to scroll down to this textbox (I would prefer that it remains out of view at the bottom of the page). This probably sounds odd, but I do have a need for it!

I make the cursor appear using this code:

<script>document.getElementById('textbox1').focus()</script>

Is anyone able to modify this code such that scrolling will not occur?

2

1 Answer 1

1

The window object supports a scrollTo() method try adding it after focus()

document.getElementById('textbox1').focus(); window.scrollTo(0,0);
Sign up to request clarification or add additional context in comments.

Comments

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.