Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6477381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:56:29+00:00 2026-05-25T06:56:29+00:00

My program allows a user to click a button and then a table row

  • 0

My program allows a user to click a button and then a table row gets up into the table via ajax. What I need is for the focus to be on the text field in that row ready for the user to add data into.

My ajax ruby code:

if( $('#effort_<%= @project_task.id %>').length == 0 )
  $('#task_list').prepend('<tr><td><%= @project_task.project.project_number %> <%= @project_task.project.project_name %> - <%= @project_task.task_name %></td>' +
                         '<td><%= text_field :effort, :hours, :name => 'effort_' + @project_task.id.to_s, :id => 'effort_' + @project_task.id.to_s, :size => 20 %></td>' +
                         '<td><%= link_to image_tag('icons/delete.png'), "Delete", :method => :delete, :confirm => "Are you sure?", :remote => :true, :title => "delete row", :class => "delete" %></td></tr>' );

:autofocus => true doesn’t work.
My main problem is getting the autofocus to work on the LAST row that is added and also only on the rows that are ADDED. The table is filled with other rows that haven’t been added, so when the user loads the screen and hasn’t added anything the autofocus shouldnt exist.

This is a hard one and I need to be pointed in the right direction.

Update
Generated html when a row is added:

   <tr>
     <td>S006T  - Project</td>
        <td>
          <input id="effort_5" type="text" size="20" name="effort_5">
        </td>
     <td>
        <a class="delete" title="delete row" rel="nofollow" data-remote="true" data-method="delete" data-confirm="Are you sure?" href="Delete">
        <img src="/images/icons/delete.png?1314715563" alt="Delete">
        </a>
     </td>
   </tr>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:56:30+00:00Added an answer on May 25, 2026 at 6:56 am

    Immediately after you prepend the new row to the list, just call jQuery focus() on the added element:

    $('#effort_<%= @project_task.id.to_s %>').focus();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a program which allows users to input some information which then gets
I have a program that allows a user to type java code into a
I am trying to run a test program that allows a user to click
I have a program that allows the user to enter a level number, and
I am finishing off a C# ASP.NET program that allows the user to build
I have a program where i use a modal popup that allows the user
Backgorund I am currently writing a program that allows a user to select a
I am creating a program that allows the user to select a drive letter
I have created the output for a program that allows a user to input
I'm writing a program that allows the user to browse their computer for images.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.