function updateUrl() { console.log("inside updateUrl function"); const baseUrl = "/CustomOrderItemAdd?storeId=385303&langId=-1&calculationUsageId=1&URL=AjaxOrderItemDisplayView&calculateOrder=1&authenticate=0&orderId=.&isDirectLink=true&promoCode="; let selectedEntries = []; let quantityEntries = []; let catEntryIndex = 2; // Get the first checkbox and check if it's selected const firstCheckbox = document.querySelector('.custom-checkbox'); if (firstCheckbox.checked) { selectedEntries.push(`catEntryId_1=${firstCheckbox.value}`); quantityEntries.push(`quantity_1=1`); } // Loop through other checked checkboxes document.querySelectorAll('.upsellOptions input[type="checkbox"]:checked').forEach(function(checkbox) { if (checkbox !== firstCheckbox) { selectedEntries.push(`catEntryId_${catEntryIndex}=${checkbox.value}`); quantityEntries.push(`quantity_${catEntryIndex}=1`); catEntryIndex++; } }); // Build the final URL var finalUrl = baseUrl + (selectedEntries.length ? '&' + selectedEntries.join('&') + '&' + quantityEntries.join('&') : ''); // Update the href attribute of the link var linkElement = document.getElementById('certificationLinkBuy'); var linkElement2 = document.getElementById('certificationLinkBuyPop'); if (linkElement) { linkElement.href = finalUrl; linkElement2.href = finalUrl; console.log("Updated href:", linkElement.href); // Log the updated href } else { console.log("Element with id 'certificationLink' not found"); } }