I would like it so that when someone clicks on a '.propertyRateTable' element, ONLY the checkbox next to it becomes checked (See image for reference). The code below simply checks every checkbox (As they all have the same class). Any suggestions?

        function clickTables()
                 $('.dateCheckbox').prop('checked', true);

enter image description here

  • as this is a jQuery question, you can also get support from stack Overflow – cropredy Nov 13 '15 at 21:07

You can provide an Id to each checkbox and use the '#' instead of '.' for checking the checkbox. Ofcourse, you would need to identify which element got clicked and then only the corresponding checkbox can be checked. But you have not provided any markup for those elements here. So I can't provide further details. :(

| improve this answer | |
  • The checkboxes are in an apex:repeat tag. Is it possible to apply an id to each one individually? – Alex Brigham Nov 13 '15 at 16:37
  • @AlexBrigham kausDix75 is right, that's the only way to do it using jQuery. It may be worth sharing relevant code here as this could probably be achieved not using jQuery, such as a Wrapper Class. – Dan Jones Nov 13 '15 at 16:46
  • Yes, I know it works! What I'm wondering about her response is it possible to assign individual ids to the checkboxes when the checkboxes are declared within apex:repeat @Poet – Alex Brigham Nov 13 '15 at 16:49
  • Yes - you can assign an Id like <fixed-text> + '-' + <counter> – kausDix75 Nov 13 '15 at 17:01

As kausDix75 mentioned, you need to provide unique id to each element. Now inside apex:repeat tag, you need to specify a counter so that it will increase for each loop of apex:repeat. Then you can append this counter to the element id. For example:

<apex:variable value="{!1}" var="rowNumber"/>
<div id="tableId{!rowNumber}"/>
<apex:variable var="rowNum" value="{!rowNumber + 1}"/>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.