lundi 4 février 2019

How to disable input fields per row if its checkbox is checked?

I couldn't find a solution to my particular problem, although there were a lot of topics about similar issues.

My code disables all the fields my table contains instead of disabling only a row per checked checkbox.

  <tr>
    <td><input type="text" name="pageName[]"></td>
    <td>
      <select name="pageSelection[]">
        <option selected>-- Select --</option>
        <option>...</option>
      </select>
    </td>
    <td>
      <input type="text" name="pageData[]">
    </td>
    <td>
      <input type="checkbox" name="disableRow[]">
    </td>
  </tr>
  <tr>
    <td><input type="text" name="pageName[]"></td>
    <td>
      <select name="pageSelection[]">
        <option selected>-- Select --</option>
        <option>...</option>
      </select>
    </td>
    <td>
      <input type="text" name="pageData[]">
    </td>
    <td>
      <input type="checkbox" name="disableRow[]">
    </td>
  </tr>

My jQuery code:

$("input:checkbox[name^='disableRow']").on("click", function(){
      $("table tr input:text, table tr select").prop("disabled", this.checked);
});

I unluckily tried to concatenate the code below:

.has("input:checkbox(:checked)")




Aucun commentaire:

Enregistrer un commentaire