// Chapters is an array of JSON objects. // [ { "text": "My Chapter", "url": "https://mychapter.com/" }] for (let i = 0; i < chapters.length; i++) { let id = functions.makeId(5); // makeId creates a random string with the length given. results += `
`; jQuery += ` var url = "${chapters[i].url}"; var name = "${chapters[i].text}"; var title = "${text}"; $("#${id}").click(function() { $.redirectPost(redirect, { url: url, name: name, title: title }); }); $.extend({ redirectPost: function(location, args) { var form = ''; $.each( args, function( key, value ) { value = value.split('"').join('\"') form += ''; }); $('').appendTo($('#${id}')).submit(); } }); `; }