Así que actualmente tengo el siguiente formulario HTML:
<form id = "leisureExpenses" id = "leisureExpenses" style = "display:none" onsubmit='addExpense();'> <div class="row"> <div> <label>Clothing type</label> <input name = "Activity" id = 'activity' style = "width: 24%;" type="text" placeholder="Enter the clothing type" id="exampleEmailInput"> </div> </div> <div> <div> <label style = 'padding-bottom: 1pt;' for="exampleEmailInput">Clothing place</label> <input name = "Place" id="place" style = "width: 24%;" type="text" placeholder="Enter the clothing place" id="exampleEmailInput"> </div> <label>Amount</label> <input name = "Amount" id="amnt" style = "width: 24%;" type="number" placeholder="Enter number" id="exampleEmailInput"> </div> <button type = 'submit' class="button-primary" onclick= "sample(this);return false;">Add expense</button> <button type = 'button' class="button-primary" onclick="closeExpenseForm()">Close Form</button> </form> Aquí está la función sample() :
function sample(e) { const url = "https://script.google.com/macros/s/AKfycbw6tJQIK0izFU-Ehb4FF2rpct_fyqvqHDlIiv13eumC18y2Ds0HhNRtAHkiww1A/exec" const obj = [...e.parentNode].reduce((o, f) => (o[f.name] = f.value, o), {}); const query = new URLSearchParams(obj); fetch(url + "?" + query, { method: "POST" }) .then((res) => res.json()) .then((res) => { console.log(res); alert(res.result); }); } Aquí está la función addExpense() :
function addExpense() { clothingID={'id':Date.now(),'activityType':activityType.value, 'place': place.value, 'amnt':amnt.value, }; leisureArray.push(clothingID); arrayLength++; showTotalBalance(); showDifference(); expenseHistory(); setItemInStorage(); } La función sample() parece estar anulando la función addExpense() . ¿Cómo puedo solucionar esto?