39 lines
972 B
JavaScript
39 lines
972 B
JavaScript
const r = (callback) => window.addEventListener('DOMContentLoaded', callback);
|
|
const g = (name) => document.getElementById(name);
|
|
|
|
r(() => {
|
|
g('submit').addEventListener('click', async () => {
|
|
const frase = g('frase').value;
|
|
const response = await fetch('/calcula', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
'frase': frase
|
|
})
|
|
})
|
|
const resultat = await response.text();
|
|
g('response').innerHTML = resultat;
|
|
});
|
|
|
|
const afegirPart = (t) => {
|
|
const frase = g('frase');
|
|
let conector = ' de ';
|
|
|
|
if (frase.value === '') {
|
|
conector = 'la ';
|
|
}
|
|
|
|
g('frase').value = g('frase').value + conector + t;
|
|
}
|
|
|
|
g('absencia').addEventListener('click', () => {
|
|
afegirPart('absencia')
|
|
});
|
|
|
|
g('presencia').addEventListener('click', () => {
|
|
afegirPart('presencia')
|
|
});
|
|
})
|