How to focus cursor to field? Please help!

Discussion in 'JavaScript' started by monkeyclap, Mar 4, 2012.

  1. #1
    Hi,

    I have the following piece of code for a Google Custom Search Engine, but I can't figure out how to automatically focus to the search box.

    Any ideas, or if it's possible?

    Cheers

    
    <script src="http://www.google.com/jsapi" type="text/javascript"></script>
    <script type="text/javascript"> 
      google.load('search', '1', {language : 'en'});
      google.setOnLoadCallback(function() {
        var customSearchControl = new google.search.CustomSearchControl('mysiteid');
        customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
        var options = new google.search.DrawOptions();
        options.setAutoComplete(true);
        options.enableSearchboxOnly("http://www.mysite.com/");    
        customSearchControl.draw('cse-search-form', options);
      }, true);
    </script>
    
    Code (markup):

     
    monkeyclap, Mar 4, 2012 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    You can't and this is why:
    This code probably displays the search form as a iframe and you can't access the document object inside the iframe from the document that holds the iframe
     
    nabil_kadimi, Mar 5, 2012 IP
    monkeyclap likes this.
  3. monkeyclap

    monkeyclap Active Member

    Messages:
    836
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #3
    I thought that would be the case. Thanks for your help though!
     
    monkeyclap, Mar 5, 2012 IP
  4. monkeyclap

    monkeyclap Active Member

    Messages:
    836
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #4
    Sorry but I don't understand... :( I guess what I'm after is this - if you look at the Google homepage the cursor's focussed on the search box automatically.
     
    monkeyclap, Mar 6, 2012 IP