To set the cursor on a particular field and automatically open the keyboard on page load without the user needing to touch the text field, you can use the HTML autofocus attribute and the JavaScript focus() method.

Here's how you can achieve this:


<input type="text" id="targetField" autofocus />


window.addEventListener('load', function() { var targetField = document.getElementById('targetField'); targetField.focus(); });


  1. The autofocus attribute is added to the target text field in the HTML. This attribute tells the browser to set the focus on this element when the page loads.

  2. In the JavaScript code, we use the window.addEventListener to attach a 'load' event to the window object. This event fires when the page has finished loading.

  3. In the event listener function, we retrieve the target text field using document.getElementById('targetField').

  4. We then call the focus() method on the target field to set the cursor in the field and automatically open the keyboard. The focus() method programmatically gives focus to an element.

With this setup, when the page loads, the cursor will be automatically set to the target text field, and the keyboard will open without the user having to touch the text field. Note that this behavior may vary depending on the user's device and browser settings. Some mobile browsers may prevent the keyboard from opening automatically for security reasons.

Have questions or queries?
Get in Touch