Show modal on click from radio button input

11,400

You should use $('#myModal').modal('show'); if the input no is checked

$('input[name="bn"]').change(function() {
   if($(this).is(':checked') && $(this).val() == '0') {
        $('#myModal').modal('show');
   }
});

Demo: https://jsfiddle.net/IA7medd/pd86o68u/2/

Share:
11,400
Alex P
Author by

Alex P

Updated on June 04, 2022

Comments

  • Alex P
    Alex P almost 2 years

    I have two radio buttons. Yes and No. For yes, on click it will show a download button underneath which works fine with the current HTML and Javascript. Now when you select the "No" radio button, I want it to display a modal with information. I already have the modal implemented and working as a separate button, but I haven't found any solutions to show the modal upon radio button input for no.

    Here is the current Javascript that I have for show/hide from radio button input for divs.

        $(document).ready(function(){
          $("input[name$='bn']").click(function(){
          var radio_value = $(this).val();
          if(radio_value=='0') {
            $("#contact").fadeIn("slow");
            $("#dlcert").fadeOut("slow");
           }
          else if(radio_value=='1') {
            $("#dlcert").fadeIn("slow");
            $("#contact").fadeOut("slow");
            }
          });
          $('[name="bn"]:checked').trigger('click');
        });
    

    jSFiddle