Need to create a list of different links on a page with the same variable appended to the end of each url.
e.g.:
https://example.tfaforms.net/formA?urlParam=ABCDEFG
https://example.tfaforms.net/formB?urlParam=ABCDEFG
https://example.tfaforms.net/formC?urlParam=ABCDEFG
https://example.tfaforms.net/formD?urlParam=ABCDEFG
FormAssembly provide an example on this page where they demonstrate how to create a repeatable section on a page with dynamic clickable links using Javascript to replace the url appended parameter in html code:
https://www.formassembly.com/blog/dynamic-clickable-links/
**They use this html code: **
<a href="https://instanceName.tfaforms.net/secondFormID?urlParam=#" class="clickableLink">Text to display for your link</a>
Alongside this javascript:
<script
src="https://code.jquery.com/jquery-3.2.0.min.js"
integrity="sha256-JAW99MJVpJBGcbzEuXk4Az05s/XyDdBomFqNlM3ic+I="
crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
//declares function to replace href in hyperlink text with value of a field in repeat section
function dynamicLinks(linkClass, fieldId) {
//creates selector statement with fieldId
var selection = 'input[id^="' + fieldId + '"]';
//intializes array to store new links
var linkArr = [];
//adds links to array from field in repeat section
$(selection).each(function() {
linkArr.push($(this).val());
});
//replaces the class of hyperlinks with values from the link array
$(linkClass).attr("href", function(i, origLink) {
return origLink.replace(/#/, linkArr[i]);
});
};
// This is the field ID to update with your value from Salesforce field ID
dynamicLinks(".clickableLink","tfa_2");
});
</script>
However, my use case is multiple links off of a contents-like list, all with the same urlParam=# at the end of the urls. Also I do not need the repeatable section functionality just need the Javascript to find all # in html and replace with the same tfa_2.
Using the FormAssembly example code I thought I could build out the html on each line of links and it would replace each # with the tfa_2 – however, it only performs the replace function on the first link.