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

318
Visualizações
Submit a form only when 'enter' key is pressed

I have an input like this which submits a form on key-up event:

<input id="filter_package_byidphrase" asp-for="@Model.FilterByPackageIdPhrase" class="package_list_list_filter_controll_input" onkeyup="this.form.submit()">

I want the form to be submitted only when 'enter' is pressed (up). I already tried solution like this, but it didn't work:

 <input id="filter_package_byidphrase" asp-for="@Model.FilterByPackageIdPhrase" class="package_list_list_filter_controll_input" onkeyup="keypressHandler">

 <script type="text/javascript">
      function keypressHandler(e)
      {
           if(e.keyCode == 13) {
                 e.preventDefault();
                 $('#filterform').submit();
           }
      }
 </script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It might be helpful to trigger the function inside the tag from the parent. Like this

<form id="myform" onsubmit="event.preventDefault()">
    <input type='text' id='input' onkeyup="keypressHandler(event)" />
</form>
<script>
    function keypressHandler(e) {
        if(e.keyCode == 13)
           myform.submit();
    }
</script>
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