Jon Harding
Jon Harding

Reputation: 4946

select radio button based on value

I have a shopping cart that is generating the radio button list. Unfortunately the generated list is repeating ID's so I can't use those as selectors. An example of the radio button generated is

<input type="radio" name="ShippingMethodID" id="ShippingMethodID9" value="68|Priority Mail Express International|59.22|0.00">

The only unique thing is the number at the beginning of the value. How can I create a selector based on the number at the beginning of the value?

I've been searching and found how to find something based on the value. But I'll need to hide it as an option

str.toLowerCase().indexOf("68")

Upvotes: 0

Views: 322

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074266

You can use an attribute-starts-with selector:

var radio = $("input[type=radio][value^=68]").

or possibly:

var radio = $("input[type=radio][value^=68|]").

(Just in case there's one with a value like 689.)


That said:

Unfortunately the generated list is repeating ID's so I can't use those as selectors.

That needs fixing. Repeating id values is invalid.

Upvotes: 2

Related Questions