Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery - Find textbox values within a table through $.each loop

Tags:

jquery

textbox

I have one HTML Table... This HTML table's first row is a static, when they click one (+) button means, the rows will added dynamically, the user want to delete one row means, he click one(-) button means current row is delete.

Each row have 4 text-boxes. My Jquery code is give below..

var FirstName;
var LastName;
var Email;
var PhoneNumber;
 $("#tableId tr").find('fieldset').each(function (i) { 
                    FirstName =FirstName +','+ $("#txtFirstName" + (i + 1) + "").val();
                    LastName =LastName +','+ $("#txtLastName" + (i + 1) + "").val();
                    Email =Email +','+ $("#txtEmail" + (i + 1) + "").val();
                    PhoneNumber = PhoneNumber+','+ $("#txtPhoneNumber" + (i + 1) + "").val();
                });

I set the text-boxes id's are dynamically,its working fine, but when the user delete one row means i cant get the text-boxes value based on Id.

How do i get the text-boxes values ?

like image 790
Manikandan Sethuraju Avatar asked Jan 17 '23 03:01

Manikandan Sethuraju


1 Answers

I'm using the index to access the four text fields. Also added the $fieldset as a context.

$("#tableId").find('tr fieldset').each(function (i) { 
    var $fieldset = $(this);
    FirstName =FirstName +','+ $('input:text:eq(0)', $fieldset).val();
    LastName =LastName +','+ $('input:text:eq(1)', $fieldset).val();
    Email =Email +','+ $('input:text:eq(2)', $fieldset).val();
    PhoneNumber = PhoneNumber+','+ $('input:text:eq(3)', $fieldset).val();
});
like image 67
T. Junghans Avatar answered Jan 31 '23 07:01

T. Junghans