tags:

views:

32

answers:

3

Good Day,

I have a table of radio buttons that have an ID value that contains an item number

How can I use jQuery to iterate through all the radio buttons that start with "rb" to determine which # number was selected?

I have something like:

return_type = $("input:radio["@name=rb*"]:checked").val();
if (return_type == undefined) {
    alert("you did not select a radio button");
}

but this doesn't work the way I selected. Is this right?

TIA,

coson

A: 
return_type = $("input:radio["@name^=rb"]:checked").val();

That should work. Starts with is ^=

EDIT: I noticed that your code is wrong in other places as well. I was too narrow in what I was looking at. Here is an update:

return_type = $("input:radio[name^='rb']:checked").val();
spinon
A: 

If you need to filter the name property of those radio buttons use

return_type = $('input:radio[name^=rb]:checked');

See: http://api.jquery.com/attribute-starts-with-selector/

jAndy
A: 

$('input:radio[name^=rb]:checked').val() should do it. You don't need the @ anymore, nor the extra quotes.

Ken Redler