Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

317
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!