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

On Fri, Jul 23, 2010 at 3:15 PM, Bob S. [email protected] wrote:

I’m trying to set the focus to the first (and only} field on a search
form and having no luck.

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

For one thing, there is no HTML tag named “search”; you’re probably
looking for an “input” … :slight_smile:


Hassan S. ------------------------ [email protected]
twitter: @hassan

or

<%= javascript_tag(’$(“search”).focus();’) %>

as part of a view…

Bob

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

$(“search”).focus();

did just fine

Bob

Bob S. 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,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs