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

424
Visualizações
How do you submit parameters from a input tag into a form onsubmit attribute in HTML?

I have 3 inputs, and I want to put their values into the form onsubmit attribute function. Here's my current code. I would like a way to do this that won't require me to create 3 variables using getElementById() or querySelector(), preferably in the HTML file, but if it's impossible, I'll accept defeat.

    <form id="form" onsubmit="addUserCredentials(userID, username, email)">
      <input type="text" id="userID" name="userID"></input>
        <label for="userID">User ID</label>
      
      <input type="text" id="username" name="username"></input>
        <label for="username">Username</label>
      
      <input type="text" id="email" name="email"></input>
        <label for="email">Email Address</label>

      <button>Submit</button>
    </form>

p.s. here's script.js if you want to look (and yes, i'm using firebase)

function addUserCredentials(userId, username, email) {
  db.ref('users/' + userId).set({
    username: username,
    email: email
  });
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The inputs will always be available in the form object with its name as the key and does not require to be passed as parameters so,

<form id="form" onsubmit="addUserCredentials()">
function addUserCredentials() {
  const userId = this.userID.value
  const username = this.username.value
  const email = this.email.value
}

this as the form element.

about 4 years ago · Juan Pablo Isaza Relatório
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