Solution: Use a unique identifier in each result to create a unique HTML ID attribute. Pass the current post's custom field value into the click handler using a parameter set to the custom field value.
<input type="text" value="[types field='code'][/types]" id="DiscountCode-[types field='promotion-id' output='raw'][/types]"></div> <button onclick="myFunction('DiscountCode-[types field='promotion-id' output='raw'][/types]')">Copy text</button>
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.