Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

258
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda