When clicking a radio button, disable the textarea

Asked

Viewed 109 times

0

How do I to disable the textarea by clicking on a radio button that is listed according to the information coming from a database. Look below:

inserir a descrição da imagem aqui

I would like to click on Not, the textarea of reference justification was disabled. The initial code is thus:

while($jmListar = mysqli_fetch_object($sqlListar)){
$listar .= "<td>
          <div class='radio-group'>
              <label class='radio-label'>
                  <input name='Cancelar_$jmListar->IdCadastros' type='radio' checked='checked' value='S' id='sim'>
                  <span class='inner-label' style='color: #008000; font-weight: bold'>Sim</span>
              </label>
              <label class='radio-label'>
                  <input name='Cancelar_$jmListar->IdCadastros' type='radio' value='N' id='nao'>
                  <span class='inner-label' style='color: #F00; font-weight: bold'>Não</span>
              </label>
           </div>
         </td>";
$listar .= "<td><textarea name='Justificativa_$jmListar->IdCadastros' class='form-control' id='justificativa' disabled></textarea></td>";
$listar .= "</tr>";
}

2 answers

2

You can take the event . change the radiobutton

<input ... class="rButton">
<input ... class="rButton">
<textarea id="justificativa">
Script

​$( ".rButton" ).change(function() {
    switch($(this).val()) {
        case 'S' :
        $("#justificativa").prop("disabled", false);
            break;
        case 'N' :
            $("#justificativa").prop("disabled", true);
            break;
    }            
});​
  • Hello Danielle. The dvd solution served for what I was needing. Thank you so much anyway.

  • blz. good luck..

1


You can do it this way:

$("input[type='radio'][name*='Cancelar']").click(function(){

   $(this).closest("tr")
   .find("textarea")
   .prop("disabled", $(this).val() == "S" ? false : true);

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>
          <div class='radio-group'>
              <label class='radio-label'>
                  <input name='Cancelar_1' type='radio' checked='checked' value='S' id='sim'>
                  <span class='inner-label' style='color: #008000; font-weight: bold'>Sim</span>
              </label>
              <label class='radio-label'>
                  <input name='Cancelar_1' type='radio' value='N' id='nao'>
                  <span class='inner-label' style='color: #F00; font-weight: bold'>Não</span>
              </label>
           </div>
         </td>
<td><textarea name='Justificativa_2' class='form-control' id='justificativa'></textarea></td>
</tr>

<td>
          <div class='radio-group'>
              <label class='radio-label'>
                  <input name='Cancelar_2' type='radio' checked='checked' value='S' id='sim'>
                  <span class='inner-label' style='color: #008000; font-weight: bold'>Sim</span>
              </label>
              <label class='radio-label'>
                  <input name='Cancelar_2' type='radio' value='N' id='nao'>
                  <span class='inner-label' style='color: #F00; font-weight: bold'>Não</span>
              </label>
           </div>
         </td>
<td><textarea name='Justificativa_$jmListar->IdCadastros' class='form-control' id='justificativa'></textarea></td>
</tr>
</table>

  • Perfect dvd. It worked! Thank you so much again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.