-1

I would like to ask what's wrong with this code, it seems legit to me.

When I select the radio button, my radioMininum still remains 0.

var radioMinimum=0;

$('#mMininum').click(function(){
        if($(this).is(':checked')){
            radioMinimum = 1;
            alert(radioMinimum);
        }
        else{
            radioMinimum=0;
            alert(radioMinimum);
        }
});

alert(radioMinimum);

inside the if-else the radioMinimum displays correctly. like if checked,its 1. but the bottom alert-outside .click radioMinimum still displays 0.

1 Answers1

2

Everything appears to be working as expected:

var radioMinimum = 0;

$('#mMininum').click(function(){
        if($(this).is(':checked')){
            radioMinimum = 1;
            console.log(radioMinimum);
        }
        else{
            radioMinimum=0;
            console.log(radioMinimum);
        }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" id="mMininum">Minimum</input>
abc123
  • 17,855
  • 7
  • 52
  • 82
  • but if i display the radioMinimum after the .click it displays 0 still – phloxangrex Nov 07 '16 at 06:17
  • @phloxangrex you can't bind a .click to something that doesn't exist. please use `$(document).ready(function() {//code here});` or just add it before the `

    ` tag.

    – abc123 Nov 07 '16 at 15:02