busboy — 2011-06-12T11:49:57-04:00 — #1
My users are requesting that when they goto my search page, that the cursor already be blinking in the keyword field. Currently you have to click in there with your mouse. Is there an easy way to do this with PHP or even HTML?
anthonysterling — 2011-06-12T12:01:43-04:00 — #2
busboy — 2011-06-12T12:16:26-04:00 — #3
anthonysterling — 2011-06-12T12:51:27-04:00 — #4
busboy — 2011-06-12T12:54:32-04:00 — #5
anthonysterling — 2011-06-12T13:04:04-04:00 — #6
paul_wilkins — 2011-06-12T18:20:45-04:00 — #7
At the end of the body, just before the </body> tag, you can use this script.
Keep in mind that this depends on the value of your form identifier, and the name of the search field. In this example, the form has an id of "search" and the search field is called "q"
<input type="text" name="q">
var form = document.getElementById('search');
anthonysterling — 2011-06-13T03:39:58-04:00 — #8
Would'nt you need to ensure the document was fully loaded first?
paul_wilkins — 2011-06-13T04:26:33-04:00 — #9
Scripts can access anything that appears before them in the DOM.
The standard location to speed up your web pages is to put your scripts at the end of the body, just before the </body> tag. Coincidentally that also means that the whole DOM is available to those scripts as well, which is why putting your scripts at the end of the body has become such a very useful technique.
anthonysterling — 2011-06-13T04:27:42-04:00 — #10
Ahhh I see, thanks for that.
I wasn't sure how that would work because technically, the body element isn't closed and it would be the root node of any element you would be targeting.
I'm sure you can tell I'm a JS noob.