I'm trying to get started with AJAX and having a problem..

I'm trying to set the focus to the first (and only} field on a search
form and having no luck.
From searching with google, I came up with:

javascript_tag("Event.observe(window, 'load', function() {
  var firstForm = $A(document.getElementsByTagName('search'))[0];
  Form.focusFirstElement(firstForm);} );")

no response, though. Please help

Bob

For one thing, there is no HTML tag named "search"; you're probably
looking for an "input" ... :slight_smile:

Found the answer. I was making it much too complicated..

$("search").focus();

did just fine

Bob

or

<%= javascript_tag('$("search").focus();') %>

as part of a view..

Bob

Bob Smith wrote:

or

<%= javascript_tag('$("search").focus();') %>

as part of a view..

Bob

But never do that. JavaScript works best when it's in separate files,
not mixed with HTML.

Best,