Hi Scott,
I am actually writing code that utilizes a "field input" reference of a specific row in table consisting of multiple rows. For instance, my code must reference "Field Input 1" of a row and decide if its length is > 0; if the length of "Field Input 1" is >0, then "Field Input 2" of the same row will be disabled. This code works in the opposite manner where if the length of "Field Input 2" is >0, then "Field Input 1" is disabled.
The code must not affect field inputs of the same name in different rows. For example, if "Field Input 1" of row 1 was disabled, "Field Input 1" of row 2 must not be disabled as well.
In the actual code, "Field Input 1" is called "debit" and "Field Input 2" is called "credit". One significant issue of my code is that I am not referencing a specific row correctly. I am using a counter called "Clicks" to count the number of times the "add row" selector is clicked such that a new row is added to the collection table. Your code does not recognize the row index that is specified by my counter "Clicks", this is what you recommended $(
'#q8 .kx-repeatable > div:nth-child(3) #q17 input'
).val()
$(document).ready(function () {
$('.cf-table-block').on('blur', 'input', sumtotal);
function sumtotal () {
var DEBIT = 0; var CREDIT = 0; var DB =0; var CR = 0;
var totalDEBIT = 0; var totalCREDIT = 0; var Clicks = 0;
$('.cf-table-add-row').click(function () {
Clicks++;
if ($('#q8 .kx-repeatable > div:nth-child(Clicks) .debit input').val().legnth>0)
{
$('#q8 .kx-repeatable > div:nth-child(Clicks) .credit input').val().attr("disabled", true);
}
else if ($('#q8 .kx-repeatable > div:nth-child(Clicks) .credit input').val().length>0)
{
$('#q8 .kx-repeatable > div:nth-child(Clicks) .debit input').val().attr("disabled", true)
}
$('.cf-table-block tbody tr').each(function () {
DB = parseNumber($(this).find('.debit input').val().toFixed(2));
totalDEBIT = $('.totalDEBIT input').val(DB).toFixed(2);
CR = parseNumber($(this).find('.credit input').val().toFixed(2));
totalCREDIT = $('.totalCREDIT input').val(CR).toFixed(2);
})
$('.RAmount input').val( DB – CR).toFixed(2);
});
}
function parseNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
}
});