Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
How check condition of checkbox when uncheck/check with id of HTML

I'm using css and javascript to check condition of value of partner Code is null and 01

  1. If user checks checkbox is PARTNER, value of partnerName '01 - Elite' and value of partnerCode is '01' will send when submit
  2. If user unchecks checkbox is PARTNER, value of partnerName is 'NULL' and value of partnerCode is 'NULL' will send when submit

This is my code:

<tr>
    <th scope="row">Partner</th>
    <td colspan="0" style="margin-top: 4px;">
        <input id="parnerNameCheck" name="parnerNameCheck" type="checkbox"/><span>PARTNER</span>
    </td>
    <td>
        <select id="partnerName" name="partnerName" disabled>
            <option value="" selected>Choose One</option>
            <option>01 - Elite</option>
        </select>
    </td>
    <td>
        <input id="partnerCode" name="partnerCode" type="hidden" value="01" />
    </td>
</tr>           
    
<script>
  $('#parnerNameCheck').click(function() {
    console.log('parnerNameCheck  checked:' + $("#parnerNameCheck").is(":checked"));
    $('#partnerName').prop("disabled", !$(this).prop("checked"));
    $('#partnerCode').prop("disabled", !$(this).prop("checked"));       
  });
</script>

UPDATED:

$('#parnerNameCheck').click(function() {
    console.log('parnerNameCheck  checked:' + $("#parnerNameCheck").is(":checked"));
    $('#partnerName').prop("disabled", !$(this).prop("checked"));
    $('#partnerCode').prop("disabled", !$(this).prop("checked")); 
    $("#partnerCode").val('');
});

But when I uncheck checkbox is PARTNER, value of partnerCode is 01 still sending when submit.
So how to fix the problem? thank a lot

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

set $("#partnerCode").val('');

  $('#parnerNameCheck').click(function() {
              console.log('parnerNameCheck  checked:' + $("#parnerNameCheck").is(":checked"));
              $('#partnerName').prop("disabled", !$(this).prop("checked"));
              $('#partnerCode').prop("disabled", !$(this).prop("checked")); 
               $("#partnerCode").val('');
          });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<tr>
          <th scope="row">Partner</th>
          <td colspan="0" style="margin-top: 4px;">
                 <input id="parnerNameCheck" name="parnerNameCheck" type="checkbox"/><span>PARTNER</span>
            </td>
            <td>
                <select id="partnerName" name="partnerName" disabled>
                    <option value="" selected>Choose One</option>
                    <option>01 - Elite</option>
                 </select>
            </td>
            <td>
                <input id="partnerCode" name="partnerCode" type="hidden" value="01" />
            </td>
          </tr>

about 4 years ago · Juan Pablo Isaza Relatório

0

I believe you are missing the ability to toggle the value of partnerCode. Your updated code would only set the value of parnetCode to null and that's it.

Below is the code that would switch the values for partnerCode:

$('#parnerNameCheck').click(function() {
  console.log('parnerNameCheck: ' + $("#partnerCode").val());
  $('#partnerName').prop("disabled", !$(this).prop("checked"));
  $('#partnerCode').prop("disabled", !$(this).prop("checked")); 
  
  // Declare variables 
  var partnerCode = $("#partnerCode");
  var partnerCodeVal = partnerCode.val();
  
  // Apply condition to $("#partnerCode").val() 
  // that will switch between values
  partnerCode.val(partnerCodeVal === "01" ? "" : "01");
});

Working example - https://jsfiddle.net/ma4orbnw/1/

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda