0

I have dynamically created a row in table using jQuery by appending the form data. Now I want to add a function to edit on button click:
When user click on edit button, it should remove the row from table and assign the values again to its relevant fields in the form.

Code:

<form id="form1" >
      <input  type="text" id="input1"  />
      <input  type="text" id="input2"  />
      <input  type="text" id="input3"  />
      <input  type="text" id="input4"  />
      <input  type="submit" id="submit-btn" value="submit"  />
</form>
3
  • Where is edit code for already existing rows? You must be having some javascript or jquery events/functions.. Commented May 25, 2016 at 12:05
  • Create a jsFiddle and it'll be easier for us to help you. Commented May 25, 2016 at 12:09
  • i actully dont have anyy idea...how to edit the row...thats why i did not write any code... Commented May 25, 2016 at 12:09

1 Answer 1

1

Just try the following code... add classes to your append function in each of Td attribute...

$(document).ready(function(){

$('#mytable').on('click','.editrow',function(){

    var item1 = $(this).closest('tr').find('.td1').text();
    var item2 = $(this).closest('tr').find('.td2').text();
    var item3 = $(this).closest('tr').find('.td3').text();
    var item4 = $(this).closest('tr').find('.td4').text();
    $('#input1').val(item);
    $('#input2').val(item2);
    $('#input3').val(item3);
    $('#input4').val(item4);
    $(this).closest('tr').remove();
});  });
Sign up to request clarification or add additional context in comments.

3 Comments

i am not good in artificial inteligence ... just do jquery and other coding as my intrest..
@HashirAnwaar ...your answer work... just tell me... waht is " .editrow " ??? +1
dear @MoizAhmad " .editrow " is class given to the button of edit .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.