My script hides the input element and displays a "thanks message" after validation of the input field called emailfield
. The "thanks message" is only shown if the email field is validated. Thank you!
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="Enter your Email" required="required">
</div>
<div class="col-12" id="thank_you" style="display: none;">
Thanks for subscribing!
</div>
<div class="col-12">
<button type="submit" class="btn btn-primary-soft m-0" name="subscribe" id="nextStep">Subscribe</button>
</div>
</form>