window.onload = function () { document.getElementById('mentalAttackForm').addEventListener('submit', function (event) { event.preventDefault(); // Prevent the form from submitting the normal way const ams = parseInt(document.getElementById('ams').value, 10); const dms = parseInt(document.getElementById('dms').value, 10); const modifier = parseInt(document.getElementById('modifier').value, 0); fetch('https://gammaworld.gmgauthier.com/roll/attack/mental', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ ams: ams, dms: dms, modifier: modifier }), }) .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; } }) }); }