Easiest/best way to autofocus on the first form field on page-load?

The underlying reason for this need is actually to tighten attribution. Will explain more below.

What is being asked is what is the easiest and/or best way to have the cursor autofocus on the first field of the form upon the page loading?

We’re attempting to tighten attribution by pairing this solution with the partial entries add-on and a hidden field that defaults to the referral URL.

The referral URL seems to only populate if the user engages with the form, but sometimes users hit refresh or navigate around the site before returning to the form page, which ruins the hidden field solution.

If the cursor autofocuses on the form field then it should make note of every user’s IP address on page load due to the partial entries add-on, and the IP address field could then be cross referenced with their eventual form fill, even if they navigate away from the page to elsewhere on the site, or come back.

If that doesn’t make sense to you, no problem, we just need to have the first form field be in focus when the page loads, for every user.

Hello. There are some good suggestions in this Stack Overflow thread:

You can add an HTML field to the form and add your custom script into that field to autofocus the first field in the form. Thank you.

1 Like

Thank you for your answer.

I was able to successfully add an autofocus script to an HTML field that works on Preview, however it is not working on the live page on any browser or device I’m testing. Any idea why that would be?

If it’s working in the form preview, but not on the page, there is likely a JavaScript conflict with another plugin or theme script. You can use these steps to check for conflicts:

Let us know what you find out.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.