Ruby on Rails: Javascript: How to grob focus when the text box appears
Posted
by DerNalia
on Stack Overflow
See other posts from Stack Overflow
or by DerNalia
Published on 2010-06-18T16:14:44Z
Indexed on
2010/06/18
16:23 UTC
Read the original article
Hit count: 258
So, I have
<script type="text/javascript">
function grabFocus(){
document.getElementByID("category_name").focus();
}
</script>
<div>
<h1>New category</h1>
<br/>
<% remote_form_for :category, @category, :url=>{:action=>'ajax_create'} do |f| %>
<%= f.error_messages %>
<%= f.hidden_field :object_type %>
<p>
<%= f.text_field :name, :label=>false %>
<%= f.submit 'Create' %>
</p>
<% end %>
<br/>
</div>
and before I just had the
<script type="text/javascript">
document.getElementByID("category_name").focus();
</script>
at the bottom of the file.
but other websites suggested that I make it a function, and call it in onLoad... but the partial I'm working with (entire thing pasted above) doesn't have a body...
I'm showing the partial in the iframe that facebox uses...
ideas?
© Stack Overflow or respective owner