Oops! Something went wrong while submitting the form.
<script> document.addEventListener('DOMContentLoaded', function() { const form = document.getElementById('wf-form-Medical-Code-Form'); const input = document.getElementById('Provider-Code'); const messageDiv = document.getElementById('message'); const displayBtn = document.getElementById('display-btn'); const submitBtn = document.getElementById('submit-button'); const validCodes = ['MED490', 'MED120', 'MED778', 'MED115', 'MED372', 'MED311', 'HEAL52', 'HEAL39', 'HEAL91', 'BETTER19', 'BETTER42', 'BETTER23']; function initializeCodeUsageTracking(codes) { if (!localStorage.getItem('codeUsageCounts')) { let codeUsageCounts = {}; codes.forEach(code => { codeUsageCounts[code] = 0; }); localStorage.setItem('codeUsageCounts', JSON.stringify(codeUsageCounts)); } } // Function to set a cookie function setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days*24*60*60*1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } initializeCodeUsageTracking(validCodes); displayBtn.addEventListener('click', function(event) { event.preventDefault(); // Prevent the default anchor behavior const providerCode = input.value.trim(); if (validCodes.includes(providerCode)) { // Valid code; update usage count and set the cookie let codeUsageCounts = JSON.parse(localStorage.getItem('codeUsageCounts') || '{}'); codeUsageCounts[providerCode] = (codeUsageCounts[providerCode] || 0) + 1; localStorage.setItem('codeUsageCounts', JSON.stringify(codeUsageCounts));
// Set the 'providerAccess' cookie to 'granted' for 1 day setCookie('providerAccess', 'granted', 30);
// Simulate a click on the actual submit button for valid code submitBtn.click();
// Redirect to the product page for a valid code window.location.href = '/product/mushroom-capsules-1mg'; // Change this URL to your product page URL } else { // Invalid code; show error message and do not submit form messageDiv.innerHTML = '<p style="color: red;">Access Denied. Incorrect provider code.</p>'; } }); }); </script>