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

203
Visualizações
show/hide on radio button checked/unchecked- knockout js

I have 2 radio buttons, When I click on the option A, a particular div has to be shown, and when click on the option B, 1st div should be hidden and 2nd div should be shown. Below is the code.

<div class="form-group">
                    <input  type="radio" name="test-radio" id="test-radio-Option-A" value="true" data-bind="click: test">
                    <label for="test-radio-Option-A">Text Message</label>
                </div>
                <div class="form-group">
                    <input  type="radio" name="test-radio" id="test-radio-Option-B" value="false">
                    <label for="test-radio-Option-B">Text Message</label>
                </div>
<div style="display: none" data-bind="visible: showDiv">
                test Div
            </div>

Following is the script I tried:(coffee script)

@showPhone = ko.observable false

test: =>
    @showPhone true

using this if I click on the 1st radio button, I was able to see the div, but I don't know if its the right way Can someone please guide me through this?

Thanks.

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

0

You'll be needing the two following bindings:

  • checked: to put on your radio-buttons
  • visible: to put on your divs you want to display

your html will look like this:

<div class="form-group">
                <input  type="radio" name="test-radio" id="test-radio-Option-A" value="true" data-bind="checked: optionA">
                <label for="test-radio-Option-A">Text Message</label>
            </div>
            <div class="form-group">
                <input  type="radio" name="test-radio" id="test-radio-Option-B" value="false" data-bind="checked: optionB">
                <label for="test-radio-Option-B">Text Message</label>
            </div>
<div data-bind="visible: optionA">
            test Div A
        </div>
<div data-bind="visible: optionB">
            test Div B
        </div>

Your viewModel will need 2 boolean observables optionA and optionB for the view to bind to in this manner

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