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

  • SEARCH
  • Home
  • 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 8326899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:55:28+00:00 2026-06-09T00:55:28+00:00

How can I perform the following action using jquery? I have a table with

  • 0

How can I perform the following action using jquery?

I have a table with three rows and a header row. something like this:
When a user enters Data in “StudentId” field, “StudentFirstName” and “StudentLastName” are populated from database using jquery-Ajax. What I want to achieve is, Once a studentId is entered in first row textbox, I want to clone the first row and append it as second row and then clear the data from first row.

Hers is my Table structure:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%@ Import Namespace="MyModel.Model" %>
<div>
<table id="MyTableHeaders">
        <tr>
            <th>
                StudentId
            </th>
            <th>
                StudentFirstName
            </th>
            <th>
                StudentLastName
            </th>            
        </tr>
    </table>
</div>

<div>
<table id="MyTableData">
        <tr>
            <td>
                <input name="StudentId"/>
            </td>
            <td>
                <input name="StudentFirstName"/>
            </td>
            <td>
                <input name="StudentLastName"/>
            </td>            
        </tr>    
</table>
</div>

Here is my jquery:

$('input[name="StudentId"]').focusout(function (e) {
    e.preventDefault();
    var link = '/Student/DisplayStudentDetails';
    $.ajax({
        type: 'POST',
        url: link,
        data: { id: $('input[name="StudentId"]').val() },
        dataType: 'json',
        success: function (result) {
            $('input[name="StudentFirstName"]').val(result.FirstName);
            $('input[name="StudentLastName"]').val(result.LastName);
            $("#MyTableData tr:first").clone().appendTo("#MyTableData");
            $("#MyTableData tr:first").find("input").attr("value", "").blur();
        },
        error: function (result) {
            alert("Failed")
        }
    });
});

I am struggling with clearing data from first row and keeping data in the cloned row. With my code it clears all the rows.

Also, I noticed that cloned rows have the same field names, hence it will update all cloned “StudentFirstName” and “StudentLastName” fields with the studentId entered in first row. How should I approach this?

Any help would be appreciated.

  • 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-06-09T00:55:30+00:00Added an answer on June 9, 2026 at 12:55 am
        success: function (result) {
            var clone = $("#MyTableData tr:first").clone();
            clone.find('input[name="StudentId"]').val(result.FirstName);
            clone.find('input[name="StudentFirstName"]').val(result.FirstName);
            clone.find('input[name="StudentLastName"]').val(result.LastName);
            $("#MyTableData ").append(clone);
        },
    

    -edit-

    although, when i’ve attempted tasks such as this in the past, i’ve created template rows.
    a row that already exists but has display:none. that way if your table has no values you can always know the template row exists.

    -edit-
    if you want to add the new row at the begining, you can just use prepend instead of append.
    or the second row would be $(“#MyTableData tr”).first().after(clone)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I perform the following action using jquery? I have a table with
Using the JavaScript Native Interface of GWT I can perform the following: public native
Smarty Pants sounds like a cool idea to me: SmartyPants can perform the following
I have following requirements: Obtain action associated with NSButton using : - (SEL)action Call
Let's assume that our system can perform actions, and that an action requires some
Let's say you have a business logic method that can perform some operation across
I have the following implementation: As you can see I have a repeater (listing
In my MVC application for booking accommodation I have the following: Action to display
I recently started using android actionbars and contextual action bars (CAB). I have just
I am using the following to list the row count for all of my

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.