Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda