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,599
  • 4
  • 55
  • 114
  • 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,971
  • 3
  • 23
  • 38
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
  • 30,079
  • 5
  • 45
  • 53
0

Try this:

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