0

I have two radio buttons:

<input checked="checked" class="survey_kind_input" type="radio" value="Short">
<input class="survey_kind_input" type="radio" value="Thorough">

I have the following javascript:

if($('.survey_kind_input').checked){
    alert('in survey kind checked');
}

But it is not working. How do I successfully make the alert work?

Philip7899
  • 4,395
  • 3
  • 48
  • 105
  • do you want the alert to happen when its clicked? – depperm Jul 23 '15 at 17:23
  • possible duplicate of [Find out if radio button is checked with JQuery?](http://stackoverflow.com/questions/2272507/find-out-if-radio-button-is-checked-with-jquery) – Patrick M Jul 23 '15 at 17:28

3 Answers3

1

You're not checking properly whether it is checked or not, so it won't work. Instead, use is() and :checked to check whether it is checked:

if($('.survey_kind_input').is(':checked')){
    alert('in survey kind checked');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input checked="checked" class="survey_kind_input" type="radio" value="Short">
<input class="survey_kind_input" type="radio" value="Thorough">
ᔕᖺᘎᕊ
  • 2,821
  • 3
  • 18
  • 35
1

Either use get() to retrieve the javascript Dom element and use checked or use is(:checked)

 if($('.survey_kind_input').get()[0].checked){
        alert('in survey kind checked');
    }

or

if($('.survey_kind_input').is(':checked'){
    alert('in survey kind checked');
}
AmmarCSE
  • 29,061
  • 5
  • 39
  • 52
0

Try this:

if($('.survey_kind_input').is(":checked"){
   alert('in survey kind checked');
}
brroshan
  • 1,600
  • 15
  • 19