0

I don't know why this is proving so difficult but over two hours of googling has not solved my problem!

My code is below. I have create a very simple set of mutually exclusive radio buttons. What I want to do is when one of them is clicked it renders the relevant content into a div below. This enables the user to toggle between the information that is displated However, when I try and test the onclick function... it does not work.

Any help would be very much appreciated. See code below.

<div class="btn-group btn-group-toggle" data-toggle="buttons" id="optionBtns">
        <label class="btn btn-primary active">
          <input type="radio" name="options" id="option1" autocomplete="off" value="1" onclick="check();" checked> School </label>
        <label class="btn btn-primary">
          <input type="radio" name="options" id="option2" autocomplete="off" value="2" onclick="check();"> University </label>
        <label class="btn btn-primary">
          <input type="radio" name="options" id="option3" autocomplete="off" value="3"  onclick="check();"> Professional Learning </label>
      </div>

The JS code is below. Note - the js running log is output without any problems.

console.log("js running");
function check(){
    console.log("function works");
}
3
  • Need more info/context. This code copied into an html (with <script> tags added) works as expected in firefox and chrome. And FWIW in firefox it will not echo "function works" in the console more than once, it will increase the counter (at the right of the line). Could be based on settings. – DinoCoderSaurus Nov 23 '19 at 21:55
  • It also works for me when I take that code in isolation and put it in a new html template. I used a UI tool called Pingendo - maybe has something to do with it. I have pasted my full code into the original question – Jonathan Foster Nov 24 '19 at 9:42
  • Figured it out... needed to have set the onclick tag on the labels themselves. Thanks for looking. – Jonathan Foster Nov 24 '19 at 10:59

You must log in to answer this question.

Browse other questions tagged .