You are viewing limited content. For full access, please sign in.

Question

Question

Set radio button only on last set in collection.

asked on June 18, 2018

I need to pass a value of a field to pre-select a radio button value that exists within a collection. User's need to be able to change it and as rows are added to the collection, previous rows should not be affected.

I can get to the button group and set it using:

$("input[id^=Field348][value=" + s + "]").prop("checked", true);

but this, of course changes all of radio groups in the collection.

I have tried several different ways to to filter to last, but none have worked so far. The following seemed to be the most promising, but neither worked.

$('#q340 ul:last').find("input[id^=Field348][value=" + s + "]").prop("checked", true);
 
$('#q340 ul:last').find("input[id^=Field348]").val(s).prop("checked", true);

As always you're help is appreciated.

0 0

Answer

SELECTED ANSWER
replied on June 18, 2018

Hi Zane,

How about:

$("input[id^=Field348][value=" + s + "]:last").prop("checked", true);

cheers,

Ian

1 0
replied on June 18, 2018

Ugh, Thanks Ian.

I tried .last() and :last multiple different ways, but not this one.

I owe you a beer. But then, people probably don't drink beer in New Zealand. 

0 0
replied on June 18, 2018

No worries Zane, sometimes hard to see the wood for the trees in jquery!

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.