1

I am using an online product and for some reason when it generated the page in question the name of the radio button set is product_id_page-0[] <-- "Note the []"

What I want to do is get the ID of the selected radio button using Jquery. If I use

    var userType =$('#product_id_page-0[]:radio:checked').attr('id');
    alert("xmlvalue is: " + userType);

Nothing happens

If I use

    var userType =$('#product_id_page-0:radio:checked').attr('id');
    alert("xmlvalue is: " + userType);

I get an alert with Undefined.

I can not change the radio button name group, but I am thinking that the brackets might be breaking something here.

Please advice.

1 Answers1

1

You need to scape the meta character with the two slashes:

var userType =$('#product_id_page-0\\[\\]:radio:checked').attr('id');
    alert("xmlvalue is: " + userType);

if this is the name instead of id use:

var userType =$('[name=product_id_page-0\\[\\]]:radio:checked').attr('id');
        alert("xmlvalue is: " + userType);

see more info here

Community
  • 1
  • 1
Bhojendra Rauniyar
  • 73,156
  • 29
  • 131
  • 187