The coding is simple.
But you do not say what you query that holds the two names will be ? So I have assumed
https://YOURURL?to1=John+Travolta&to2=Jason+Statham
The simplest way is to use classes for the elements.
Also put the element sets in a group and give the groups a class name and some Additional HTML Attributes.
The code will then look for the group class qrbox and iterate each one it finds.
It will look for the Additional HTML Attributes of each and use these to know which URLSearchParams to use for each.
//https://YOURURL?to1=John+Travolta&to2=Jason+Statham
var theElements = document.querySelectorAll('.qrbox')
var paramsString = window.location.search
let searchParams = new URLSearchParams(paramsString);
theElements.forEach(qrFunction);
function qrFunction(item, index) {
var guestNameParam = item.dataset.name
var qrBoxID = item.dataset.qr
var colorDark = item.dataset.colordark
var colorLight = item.dataset.colorlight
var theTo_ = searchParams.get(guestNameParam )
thisGuestEl = item.querySelector('.theto')
var qrel = item.querySelector('.qrcode')
console.log(colorDark)
thisGuestEl.innerHTML = theTo_
//-- generate new qr code using madaffandi url + querystring
var qrcode = new QRCode(qrel, {
text: theTo_,
width: hypeDocument.getElementProperty(qrel, 'width'),
height: hypeDocument.getElementProperty(qrel, 'height'),
colorDark : colorDark,
colorLight : colorLight,
correctLevel : QRCode.CorrectLevel.H
});
}
userQR3.hype.zip (33.5 KB)