|
| 1 | +document.addEventListener('DOMContentLoaded', function() { |
| 2 | + const form = document.getElementById('remoteForm-form-ContributionPage7'); |
| 3 | + const firstName = document.getElementById('first_name').closest('.form-group'); |
| 4 | + const lastName = document.getElementById('last_name').closest('.form-group'); |
| 5 | + const email = document.getElementById('email-primary').closest('.form-group'); |
| 6 | + const creditCardNumber = document.getElementById('credit_card_number').closest('.form-group'); |
| 7 | + const cvv = document.getElementById('cvv2').closest('.form-group'); |
| 8 | + const expMonth = document.getElementById('credit_card_exp_date_M').closest('.form-group'); |
| 9 | + const expYear = document.getElementById('credit_card_exp_date_Y').closest('.form-group'); |
| 10 | + const submitButton = document.getElementById('remoteform-submit'); |
| 11 | + const amountSection = document.querySelector('label.rf-label').parentNode; |
| 12 | + const radioInputs = document.querySelectorAll('.form-check-input:not([value="54"])'); // Exclude the OSI membership checkbox |
| 13 | + |
| 14 | + // Create new div for grid layout and set it up for CSS Grid |
| 15 | + const gridContainer = document.createElement('div'); |
| 16 | + gridContainer.className = 'form-check-grid'; |
| 17 | + amountSection.parentNode.insertBefore(gridContainer, amountSection); |
| 18 | + |
| 19 | + // Move only the radio buttons into the grid container |
| 20 | + radioInputs.forEach(radio => { |
| 21 | + gridContainer.appendChild(radio.parentNode); |
| 22 | + }); |
| 23 | + |
| 24 | + // Create new div and append input fields |
| 25 | + const newDiv = document.createElement('div'); |
| 26 | + newDiv.style.display = 'none'; // Initially hidden |
| 27 | + newDiv.append(firstName, lastName, email, creditCardNumber, cvv, expMonth, expYear, submitButton); |
| 28 | + form.insertBefore(newDiv, amountSection.nextSibling); |
| 29 | + |
| 30 | + // Modify amounts display |
| 31 | + document.querySelectorAll('.form-check-label').forEach(label => { |
| 32 | + label.textContent = label.textContent.replace(/ - \$[\d\.]+/, ''); |
| 33 | + }); |
| 34 | + |
| 35 | + // Change last radio to checkbox |
| 36 | + const memberRadio = document.querySelector('input[value="54"]'); |
| 37 | + if (memberRadio) { // Check if element exists before changing |
| 38 | + memberRadio.type = 'checkbox'; |
| 39 | + memberRadio.closest('.form-check').querySelector('label').textContent = 'Yes, I want to become an OSI member!'; |
| 40 | + newDiv.prepend(memberRadio.closest('.form-check')); |
| 41 | + } |
| 42 | + |
| 43 | + // Handle button click interactions |
| 44 | + radioInputs.forEach(radio => { |
| 45 | + const label = radio.nextElementSibling; // Assuming label immediately follows input |
| 46 | + label.addEventListener('click', function() { |
| 47 | + // Uncheck all other radios |
| 48 | + radioInputs.forEach(otherRadio => { |
| 49 | + if (otherRadio !== radio) { |
| 50 | + otherRadio.checked = false; |
| 51 | + } |
| 52 | + }); |
| 53 | + // Check this radio |
| 54 | + radio.checked = true; |
| 55 | + // Manually trigger the 'change' event if necessary |
| 56 | + radio.dispatchEvent(new Event('change')); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + // Add Donate button |
| 61 | + const donateButton = document.createElement('button'); |
| 62 | + donateButton.textContent = 'Contribute'; |
| 63 | + donateButton.type = 'button'; |
| 64 | + donateButton.addEventListener('click', () => { |
| 65 | + if (newDiv.style.display === 'none') { |
| 66 | + newDiv.style.display = 'block'; |
| 67 | + donateButton.textContent = 'Cancel'; |
| 68 | + newDiv.style.transition = 'all 0.3s ease'; |
| 69 | + } else { |
| 70 | + newDiv.style.display = 'none'; |
| 71 | + donateButton.textContent = 'Contribute'; |
| 72 | + } |
| 73 | + }); |
| 74 | + form.appendChild(donateButton); |
| 75 | +}); |
0 commit comments