window.onload = function () { document.getElementById('physicalAttackForm').addEventListener('submit', function (event) { event.preventDefault(); // Prevent the form from submitting the normal way const dac = parseInt(document.getElementById('dac').value, 10); const awc = parseInt(document.getElementById('awc').value, 10); const ahd = parseInt(document.getElementById('ahd').value, 10); const modifier = parseInt(document.getElementById('modifier').value, 10); const weapon_attack = document.getElementById('weapon_attack').checked; fetch('https://gammaworld.gmgauthier.com/roll/attack/physical', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ weapon_attack: weapon_attack, modifier: modifier, dac: dac, awc: awc, ahd: ahd }), }) .then(response => response.json()) .then(data => { const resultsDiv = document.getElementById('results'); let html = ''; if (data['needed']) { html += `

Needed: ${data['needed']}      `; } if (data['original-roll']) { html += `Original Roll: ${data['original-roll']}

`; } if (data['modifier']) { html += `

Modifier: ${data['modifier']}      `; } if (data['adjusted-roll']) { html += `Adjusted Roll: ${data['adjusted-roll']}

`; } html += `
`; if (data['outcome']) { let outcomeText = data['outcome']; html += `

${outcomeText}

`; // adding img tag let outcomeImage = 'img/' + outcomeText.replace(' ', '%20') + '.png'; html += `` resultsDiv.innerHTML = html; } }) }); }