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

115
Visualizações
Accessing radio button value outside the function in javascript

I need the value of the radio button outside the function.

In the following code, the variable value returns a new value every time the radio button is pressed, however, the date value does not change.

    var date_value=2;        
    var $radios = $('input[name=daterange]').change(function () {
    var value = $radios.filter(':checked').val();
    console.log('value'+value);
    date_value = value;
    });
    console.log('date value'+date_value);

HTML

       <div id="dates" name="daterange">

      <p>
        <input type="radio" id="d1" name="daterange" value='2'/> 
        <label for="d1">24 hours</label>
        <br> 
        <input type="radio" id="d3" name="daterange" value='7'/> 
        <label for="d3">7 days</label>
        <br> 
        <input type="radio" id="d4" name="daterange" value='30'/> 
        <label for="d4">1 month</label>
</div>
about 4 years ago · Juan Pablo Isaza
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