In my BB theme, when I click on the magnifying glass in the menu, it brings up a search box (as expected). Then I have to click again in the search box to give the focus to the text input area.
How can I remove the need for that extra click and automatically give the focus to the search box’s text input area upon clicking on the magnifying glass? Then my visitors could just click on the magnifying glass and type their search terms without the need for the extra click in the text area.
That code looks correct to me, I can see that it’s being added to the pages when I view the source, and it looks like it’s targeting the correct elements, but in multiple browsers it’s having no effect.
I suspect the element targeting is where the problem may be. If I add an alert() or console.log() call inside the click-activated function, they don’t trigger, but if I just insert them as solo calls outside of any element targeting, they work. So I think the function inside the on-click isn’t getting triggered.
Thanks Danny,
Yes that worked for me…
Steve one thing to watch, copying and pasting from here will sometimes mess up the code.
Copy into a plan text editor first to preserver the code.
This is what it can look like when it does not copy/paste correctly…
Update, this paste worked because I used the code tags here, but essentially the single quotes get switched to ' (colon removed!) and other characters change too…
I thought that maybe 1000ms wasn’t enough time, so I tried changing it to 5000ms, and it worked.
Then I changed it back to 1000ms, and it continued working. Then I tried 100ms, and that works too. I’m not sure how or why this made a difference, but at least it seems to be working now. Maybe the fact that I was running the javascript console while testing the previous version was causing an issue somehow.
One oddity with this implementation is that if you click on the magnifying glass a second time after the search box is visible, the word “Search” briefly flashes in the text input area before it disappears. I think that could be fixed by removing value=“Search” from the input element.