Arton Arc
Arton Arc

Reputation: 3

Need help to get check the value of radio button list checked using jquery

http://jsfiddle.net/EwKNW/2/

I need to check whether the following radio buttonlist is checked yes or no.

I have tried with easier HTML structure its working fine ( http://jsfiddle.net/pfZUt/6/ )

I have trouble in using jquery and propagating through the HTML tree structure.

Any help will be greatly appreciated. Thanks in advance.

Upvotes: 0

Views: 311

Answers (2)

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21376

I don't understand your if else statements but you can get checked element names like this ,

 $('#myform').submit(function() {
        $('input:radio:checked').each(function(){
          alert( $(this).attr('name'));
        });
     });​

http://jsfiddle.net/pfZUt/7/

You need to remove this from second selector because it's pointing to the element_475 which tries to select inside it.

Upvotes: 2

zongweil
zongweil

Reputation: 2051

This is not actually an issue with your code. The issue in the first fiddle that you posted is that you're not loading in the jQuery library under "Choose Framework", so the following code

$('#myform').submit(function() { ...

cannot be interpreted. You can see that this is the case by (in Chrome) Right Click -> Inspect Element. You'll see an error that says "Uncaught TypeError: Cannot call method 'submit' of null". This becomes fixed once you load the jQuery library, and the code you have works fine.

You can see the effects here: http://jsfiddle.net/EwKNW/3/

Upvotes: 2

Related Questions