Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
How can I make my HTML Form have an onsubmit event and an onclick action for its submit button?

So I currently have the following HTML form:

<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>

Here is the sample() function:

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);
  });
}

Here is the addExpense() function:

function addExpense()
{

        clothingID={'id':Date.now(),'activityType':activityType.value, 'place': place.value, 'amnt':amnt.value, };
        leisureArray.push(clothingID);
        arrayLength++;
        showTotalBalance();
        showDifference();
        expenseHistory();    
        setItemInStorage();  
}

The sample() function seems to be overriding the addExpense() function. How do I fix this?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda