0

I have a form on this website: https://www.ubersmith.com/ (if you click on the little magnifying glass it displays full screen).

I have tried multiple ways to force autofocus on the field when it loads but I can't for the life of me work out why its not working. The site is built in WordPress.

Can anyone help me work this out? I've tried the autofocus and autofocus="autofocus" on the field. I have also tried the autofocus the field ID on load and on button press for the button, but nothing seems to work.

Any help would be great.

Thanks in advance.

  • Are you talking about the search form? That is not even visible when the page loads, so what sense would it make to autofocus it in the first place …? You should focus the field, when you make the form visible. – CBroe Aug 15 '17 at 09:07
  • thats what I tried.. but i'm not sure why its not working when the form is visible.. i've tried to call a js to force it to autofocus and I have had autofocus within the actual input code itself.. just seems to completely ignore it. – Chris Mitchell Aug 15 '17 at 10:15
  • I even have a script running in the form: `if (!("autofocus" in document.createElement("input"))) { document.getElementById("searchfield").focus();}` – Chris Mitchell Aug 15 '17 at 15:23
  • I doubt that if condition is actually true. Every modern browser supports the attribute on the input element, so that check should always fail. – CBroe Aug 16 '17 at 07:26
  • I have also tried to add a focus on the button click onclick="document.findElementById('searchfield').focus(); return false;" but it still doesn't work. Its just odd that I can't get it to autofocus – Chris Mitchell Aug 17 '17 at 09:08
  • findElementById does not exist, that would only throw an error, you meant getElementById. Weird thing is though, even if you execute that via the browser console, it does not show any error, but does not focus the field either. – CBroe Aug 17 '17 at 09:18
  • I just changed it to be getElementById and you're right it still doesn't work. I'm really unsure why thats not being happy. I can't see any error either, it just refuses to focus that field. – Chris Mitchell Aug 18 '17 at 07:51

1 Answers1

0

Answer was an issue with a conflicting js that was not autofocusing.. removed the conflict and it worked :)