Example javascript:searchControl.execute('google')

47 views
Skip to first unread message

duese...@gmail.com

unread,
Jul 11, 2008, 6:42:06 PM7/11/08
to Google AJAX API
Problem to fire an event to searchControl using a link event.

<pre><a href="javascript:searchControl.execute('google');">google</a></
pre>

Firebug: searchControl is not defined

url: http://webmove.org
js: http://webmove.org/include/js/webmove.js

the script uses a function 'include(file)' to load the google api
key.
by using the input field (top right of the page) searchControl.execute
works fine.

Any ideas? Thx.dan.

Ben Lisbakken

unread,
Jul 11, 2008, 8:51:49 PM7/11/08
to Google-AJAX...@googlegroups.com
Your searchControl is in the scope of OnLoad, it is not in the global scope.  When your anchor tag gets clicked, it will be looking for searchControl in the global scope.  Try changing these lines:

function OnLoad() {
   var controlRoot = document.getElementById("searchResults");
   // Create a search control
   var searchControl = new GSearchControl();

to this:

var searchControl;
functionOnLoad(){
  var controlRoot = document.getElementById("searchResults");
   // Create a search control
   searchControl = new GSearchControl();


It should work then.

Good luck,
Ben

duese...@gmail.com

unread,
Jul 12, 2008, 4:11:35 AM7/12/08
to Google AJAX API
Yep. global declaration works now fine. thx you and nice weekend ;-)

On 12 Jul., 02:51, Ben Lisbakken <lisba...@google.com> wrote:
> Your searchControl is in the scope of OnLoad, it is not in the global
> scope.  When your anchor tag gets clicked, it will be looking for
> searchControl in the global scope.  Try changing these lines:
>
> function OnLoad() {
>    var controlRoot = document.getElementById("searchResults");
>    // Create a search control
>    var searchControl = new GSearchControl();
>
> to this:
>
> var searchControl;
> functionOnLoad(){
>   var controlRoot = document.getElementById("searchResults");
>    // Create a search control
>    searchControl = new GSearchControl();
>
> It should work then.
>
> Good luck,
> Ben
>
> On Fri, Jul 11, 2008 at 3:42 PM, webmove....@gmail.com <
Reply all
Reply to author
Forward
0 new messages