| 1 |
(function() { |
| 2 |
var typeSelect = document.getElementById('pc-type'); |
| 3 |
var input = document.getElementById('pc-value-input'); |
| 4 |
var hidden = document.getElementById('pc-value-hidden'); |
| 5 |
function updatePromoInput() { |
| 6 |
if (typeSelect.value === 'fixed') { |
| 7 |
input.step = '0.01'; |
| 8 |
input.placeholder = 'e.g. 5.00'; |
| 9 |
} else { |
| 10 |
input.step = '1'; |
| 11 |
input.placeholder = 'e.g. 50'; |
| 12 |
} |
| 13 |
syncValue(); |
| 14 |
} |
| 15 |
function syncValue() { |
| 16 |
var val = parseFloat(input.value || 0); |
| 17 |
hidden.value = typeSelect.value === 'fixed' ? Math.round(val * 100) : Math.round(val); |
| 18 |
} |
| 19 |
typeSelect.addEventListener('change', updatePromoInput); |
| 20 |
input.addEventListener('input', syncValue); |
| 21 |
updatePromoInput(); |
| 22 |
})(); |
| 23 |
|