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

210
Views
Subscription button with data validation

What the script does is hide the input element and show the "thanks message". But prior to this I need it to validate if input emailfield is validated, and show the "thanks message" only if that happens. Thanks!

var nextStep = document.querySelector('#nextStep');

nextStep.addEventListener('click', function(e) {
  e.preventDefault()
  // Hide first view
  document.getElementById('my_form').style.display = 'none';

  // Show thank you message element
  document.getElementById('thank_you').style.display = 'block';
});
<form class="row row-cols-lg-auto g-2 align-items-center justify-content-end">
  <div class="col-12" id="my_form">
    <input id="emailfield" type="email" class="form-control" placeholder="Ingresa tu Email" required="required">
  </div>

  <div class="col-12" id="thank_you" style="display: none;">
    Gracias por subscribirse!
  </div>
  <div class="col-12">
    <button type="submit" class="btn btn-primary-soft m-0" name="subscribirse" id="nextStep">Subscribirse</button>
  </div>

</form>

enter image description here

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

0

var nextStep = document.querySelector('#nextStep');

nextStep.addEventListener('click', function (e) {
  e.preventDefault()

  let inputEmail = document.querySelector('#emailfield')
  if (/.*\@.*\..*/.test(inputEmail.value)) {
    // validation passed


    // Hide first view
    document.getElementById('my_form').style.display = 'none';

    // Show thank you message element
    document.getElementById('thank_you').style.display = 'block';
  } else {
    // validation not passed
  }
});

Instead of this regexp you can use any that you want

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!