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

168
Views
2 functions in the same button during submitting the form

I want to submit a form , the story that what i want exactly is when i click on the button submit" if there was an error(fields not filled) , show me message and go to a specific "id" section in the body otherwise it will jump automatically to new section tag,

I have applied that on a the button submit like that :

  <script>
    function validate() {
    if (form.errors){
      return alert('{{ message }}');
      document.getElementById('firstsectionid').scrollIntoView();
    } 
    else{
      document.getElementById('nextsectionid').scrollIntoView();
}

   </script>

code button submit:

  <button class="floated" href='#nextsectionid' onclick="validate()">Next</button>

But it doesn't give any result , help please. thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  <script>
    function validate() {
    if (form.errors){
      return alert('{{ message }}');
      // the line below will never run with a 'return' above it.
      document.getElementById('firstsectionid').scrollIntoView();
    } 
    else{
      document.getElementById('nextsectionid').scrollIntoView();
}

   </script>

try this

  <script>
    function validate() {
    if (form.errors){
      document.getElementById('firstsectionid').scrollIntoView();
      return alert('{{ message }}');
    } 
    else{
      document.getElementById('nextsectionid').scrollIntoView();
}

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