1

I am using a payment button generator for a specific selection of items that creates a pre-made radio list of prices. When you select the amount/item you want, you then click "continue" and it triggers the modal payment box (which then goes to PayPal). All of that is working great. The problem is the pre-made option gives you NO place to add descriptions or paragraphs or any other html. So I have added a list of items above using basic html and content and am now trying to trigger the corrosponding radio selector on-click.

My unordered list of items are wrapped in a basic div and each item has a custom ID.

<div id="items-container">
  <ul>
    <li id="item1"><div>my content</div></li>
    <li id="item2"><div>my content</div></li>
  </ul>
</div>

Directly below this block of code is the pre-generated form from the payment module I am using. It generates a checkbox selection for prices like this:

<form method="post" action="#">
  <ul id="prices-wrap-radio-list">
    <li>
    <input type="radio" value="10.00" id="level-1" name="price-level" data-price-id="1">
    <label for="level-1">Level 1</label>
  </li>
  <li>
    <input type="radio" value="20.00" id="level-2" name="price-level" data-price-id="2">
    <label for="level-2">Level 2</label>
  </li>
  </ul>
</form> 

(and so on). Is there any way to force the form to select the corrosponding level with the items in the list above? Can I wrap my LI tag with a link tag that triggers the checkbox for that specific item/level? Or would I need some jQuery for that?

Thanks!

RodeoRamsey
  • 498
  • 2
  • 8
  • 20
  • You will need javascript for that... If i understand correctly - if user clicks on list item -> corresponding radio button should be checked? Or vice versa? :) – sinisake Aug 24 '15 at 00:40
  • I am not clear on what exactly you are trying to accomplish. Do you want to select specific checkbox? Please explain a little more clear. – Gacci Aug 24 '15 at 00:41
  • @nevermind - exactly. Hmm. ok. – RodeoRamsey Aug 24 '15 at 00:47
  • @Gacci - Pretty much what nevermind said: User clicks on list item, corresponding radio button is checked/activted. – RodeoRamsey Aug 24 '15 at 00:48

1 Answers1

2

If JQuery is allowed:

$('li').click(function() {
$(':radio[data-price-id="'+$(this).data('level')+'"]').prop('checked', true);
});

Just give list items appropriate attributes:

<li id="item1" data-level="1"><div>my content</div></li>
<li id="item2" data-level="2"><div>my content</div></li>

EDIT: If you can't change HTML structure, try with this:

$('li').click(function() {
    index=$(this).index();
$(':radio').eq(index).prop('checked', true);
});
sinisake
  • 11,240
  • 2
  • 19
  • 27
  • Actually, working: http://jsfiddle.net/sinisake/pfj4t8fy/ just datta attributes should be set... :) – sinisake Aug 24 '15 at 00:59
  • Yours is good, too. :) This is just little easier (with small HTML changes). – sinisake Aug 24 '15 at 01:03
  • Thank you. Let me try to implement. – RodeoRamsey Aug 24 '15 at 01:06
  • Np, just wrap code in: https://learn.jquery.com/using-jquery-core/document-ready/ and include JQuery (if it isn't alredy included). Btw, @slider - your solution works just if you change attr() to prop() -? Probably related to to this: http://stackoverflow.com/questions/16051491/difference-between-prop-and-attr-in-jquery-and-when-to-use-attr-and-prop – sinisake Aug 24 '15 at 01:14
  • Looks like it works! Now if I could just get my plugin to quit stripping the data-level code from my LI's we'd be great. Thanks for your help! – RodeoRamsey Aug 24 '15 at 02:58
  • @nevermind So is there any way to accomplish this if for whatever reason I CAN'T get the data-level="n" added to my LI code? – RodeoRamsey Aug 26 '15 at 15:19
  • @RodeoRamsey, sure, give me few minutes, you have id's in list? And they have number at the end, as i see (or it was just for example)? – sinisake Aug 26 '15 at 15:56
  • @RodeoRamsey, here it is, without using of id's, you can see new code in action: http://jsfiddle.net/pfj4t8fy/5/ If it doesn't work, too, send complete HTML (maybe selectors should be changed, etc, etc...) – sinisake Aug 26 '15 at 16:03