Derek Smith wrote:
> Here is my code:
> cat login.html.erb
> <!-- Begin Login Bar -->
> <div id="login">
> <% form_tag :action => 'login' do %>
> <br />
> <label for='username'>Username:</label>
> <%= text_field_tag 'username' %>
> <label for='password'>Password:</label>
> <%= password_field_tag 'password' %>
> <%= image_submit_tag 'login.png' %>
> <br />
> <br />
> <% end %>
> </div>
> <!-- End Login Bar -->
> Yet I am still unsure how to integrate this code, maybe just the JS
> block?
This isn't really a Ruby question, but briefly: you can emit a
<script language='javascript'>
...
</script>
which does what you want. However:
1. You want this to happen when the page has finished loading, so write
it to be triggered on the onload event.
2. It's cleaner to put it in the <HEAD> of your document, which could be
in the layout or using content_for :head
3. It's cleaner to put it in a separate Javascript file, e.g.
public/javascripts/focus_user.js, and then all you need is:
<%= javascript_include_tag 'focus_user' %>
This sort of stuff is wonderfully easy to do using jQuery, and I
recommend it strongly. All you would need is:
jQuery( function($) {
$('#username').focus();
});
--
Posted via http://www.ruby-forum.com/.