Zahirabbas
Zahirabbas

Reputation: 1119

check is radio element checked in ajax response

I have ajax response containing two radio element.i want to check if radio element is checked in response.

I m using below code to check radio status but not working.

  $('#input[type=radio]').each(function(){
 alert($(this).attr('checked'));
});

as i know this is not working due to ajax response. but how to fire js code to check even in ajax resoponse.

any help would be much appreciate.

Upvotes: 0

Views: 383

Answers (4)

Jai
Jai

Reputation: 74738

Your issue is your selector which contains # for id:

$('#input[type=radio]')
//-^------------------------# is used to select an id not the tags

try this:

$('input[type="radio"]').each(function(){
    alert(this.checked); // returns "true" if checked/ "false" if not checked
});

Upvotes: 0

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

try this:

$(document).find('input[type="radio"]').each(function(){
   if($(this).is(':checked')){
      //your code
   }
});

Upvotes: 1

user3401335
user3401335

Reputation: 2405

use prop

  $('input[type=radio]').each(function(){
 alert($(this).prop('checked'));
});

and #input only if your radio have id="input". if you want check all radio, could be only

input[type=radio] 

as the example

Upvotes: 0

Sridhar R
Sridhar R

Reputation: 20418

Try this

$('#input[type=radio]').each(function(){
 if($(this).is(':checked')){

 }
});

Upvotes: 0

Related Questions