4

I need to test if the BootStrap radio button is checked. Here is my approach but it does not work. How could I verify if the radio button is Checked?

<script>
    function optChange() {
          if (document.getElementById("optEventType").val() == 'yes'){
            /// Do something.....
           }
    }
</script>

<form>
   <div id ="optType" onchange="optChange()" class="radio">
        <label><input type="radio" name="opt1" id = "opt1">Tex21 </label>
        <label><input type="radio" name="opt1" id = "opt2">Text2</label>
    </div>
</form>
Ben Harrison
  • 2,121
  • 4
  • 24
  • 40
CoderInside
  • 473
  • 1
  • 4
  • 17

1 Answers1

7
if ($("#opt1").is(":checked"))) {
  // do A
}

else if ($("#opt2").is(":checked")) {
  // do B
}

You have a similar answer here: jQuery, checkboxes and .is(":checked")

But I saw that you used ids attributes in the options so I use it for your answer..

Community
  • 1
  • 1
ItayB
  • 10,377
  • 9
  • 50
  • 77