How do I get the cursor to defualt into the custom google search box?

Discussion in 'HTML & Website Design' started by WebdevHowto, Feb 6, 2008.

  1. #1
    Has anyone had any luck getting the cursor to default in the google search box? It is against TOS to change the code from google so I am having trouble figuring out how to do this. :(

    Any ideas?
     
    WebdevHowto, Feb 6, 2008 IP
  2. ToddMicheau

    ToddMicheau Active Member

    Messages:
    183
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    If you are talking about a google search like in this site here:

    http://www.usfca.edu/osp/google_search.htm
    (Randomly found)

    Then what your looking for is easy enough to do- without changing their code:

    
    <script language="javascript">
    var googleSearchBar = document.getElementsByName("q");
    googleSearchBar[0].focus();
    </script>
    
    Code (markup):
    Place that under their code and it will automatically set the focus to their text field.
    (Note: If you by some obscurely random chance have an element named "q" as well then you will need to edit the code to target the correct element.)
     
    ToddMicheau, Feb 6, 2008 IP
    WebdevHowto likes this.
  3. WebdevHowto

    WebdevHowto Peon

    Messages:
    991
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Todd,

    I have been looking 2 days for that. Rep added :)
     
    WebdevHowto, Feb 6, 2008 IP