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

178
Visualizações
How to select two input fields with one radio button

So what am trying to do is bind two inputs fields into one radio button for users to select. The values for input fields will be generated dynamic but present for selection with a single radio button. I tried doing it bootstrap but did not work.

<!-- Twitter-Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">



<!-- Body -->
<div class="form-check form-check-inline">
  <input class="form-check-input" id="bind1" type="radio" name="name1" id="inlineRadio" value="valu1">
  <input class="form-check-input" id="bind2" type="radio" name="name2" id="inlineRadio" value="valu2">
  <label class="form-check-label" for="inlineRadio">1</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" id="bind1" type="radio" name="name1" id="inlineRadio" value="val8">
  <input class="form-check-input" id="bind2" type="radio" name="name2" id="inlineRadio" value="val12">
  <label class="form-check-label" for="inlineRadio">2</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" id="bind1" type="radio" name="name1" id="inlineRadio" value="valu78">
  <input class="form-check-input" id="bind2" type="radio" name="name2" id="inlineRadio" value="890">
  <label class="form-check-label" for="inlineRadio">3</label>
</div>

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

0

you should add the same name for every 2 buttons to make them work as expected.

note: id should be unique in your HTML

<!-- Twitter-Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">



<!-- Body -->
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="name1" value="valu1">
  <input class="form-check-input" type="radio" name="name1" value="valu2">
  <label class="form-check-label" >1</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="name2" value="val8">
  <input class="form-check-input" type="radio" name="name2" value="val12">
  <label class="form-check-label" >2</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="name3" value="valu78">
  <input class="form-check-input" type="radio" name="name3" value="890">
  <label class="form-check-label" >3</label>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

This solution will cause all sibling radio buttons to be selected when one is selected.

var buttons = document.querySelectorAll('.form-check-inline input:first-child');
for (var i = 0; i < buttons.length; i++) {
    buttons[i].addEventListener('click', function() {
        // this.parent.querySelectorAll('input')
        var children = this.parentNode.getElementsByTagName('input');
        for (var j = 0; j < children.length; j++) {
            children[j].checked = true;
        }
    });
}
.form-check-inline input[type="radio"]:not(:first-child) {
    display: none;
}
<!-- Twitter-Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<!-- Body -->
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="name1" id="inlineRadio" value="valu1">
  <input class="form-check-input" type="radio" name="name2" id="inlineRadio" value="valu2">
  <label class="form-check-label" for="inlineRadio">1</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="name1" id="inlineRadio" value="val8">
  <input class="form-check-input" type="radio" name="name2" id="inlineRadio" value="val12">
  <label class="form-check-label" for="inlineRadio">2</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="name1" id="inlineRadio" value="valu78">
  <input class="form-check-input" type="radio" name="name2" id="inlineRadio" value="890">
  <label class="form-check-label" for="inlineRadio">3</label>
</div>

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