Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
HTML Table - Loop through dynamically created rows and if field in specific column contains date prevent row from editing

I'm trying to create a JavaScript to disable a row if EndDate contains a date. The table is generate automatically so I thought to lookup how many rows the table has and start iterating through them. Check if fields in column EndDate contain a date. If that row contains a date then disable any field in that row.

To track down the fields I used this to check if I could disable them.

document.getElementById("r0_LineItemCode").disabled = "true";
document.getElementById("r0_LineItemCode_ref_ref").disabled = "true";
document.getElementById("pr0_LineItemCode").disabled = "true";
document.getElementById("r0_ec_type").disabled = "true";

Table

Table code

DateField

I accomplished to loop through the rows and find out how many rows there are and show the data on the console. But now selecting that field to check if it contains a date and then disable those row items fails.

Code to track down the rows and iterate through the rows:

let text = "";
var endDateFields = [];
var rowData  = document.querySelector("#RequestLinesGrid_RowIDs");
console.log(rowData);
console.log(rowData.value);
const rows = rowData.value.split(',');

rows.forEach(myFunction);

console.log(text);
console.log(r0_EndDate);
console.log(r1_EndDate);
console.log(r2_EndDate);

function myFunction(item, index) {
  text += "indexNumber = " + index + " variableField: " + item + "_EndDate";

        var str = item + "_EndDate";
        eval(str);
        console.log(str);

}

I have the feeling I'm almost there, but need a little push in the right direction :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is a simple logic of your problem, if date is not empty disable all inputs of the parent tr.

document.querySelector('table').querySelectorAll('td.date').forEach(el => {
  if (el.innerHTML !== '') {
    const parentTr = el.parentElement;
    parentTr.querySelectorAll('input').forEach(input => {
      input.disabled = true;
    });
  }
});
<table>
  <thead>
    <th>id</th>
    <th>input1 Example</th>
    <th>input2 Example</th>
    <th>date Example</th>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td><input name='test' type='text'></td>
      <td><input name='test' type='text'></td>
      <td class='date'>10/10/2021</td>
    </tr>
    <tr>
      <td>2</td>
      <td><input name='test' type='text'></td>
      <td><input name='test' type='text'></td>
      <td class='date'>10/10/2021</td>
    </tr>
    <tr>
      <td>1</td>
      <td><input name='test' type='text'></td>
      <td><input name='test' type='text'></td>
      <td class='date'></td>
    </tr>
  </tbody>
</table>

Instead of check all row just add a simple class on td have date then check it as my example.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!