Newsletter sign up form using Flex, absolute Position
Design comparison
Solution retrospective
š¤© Welcome, everyone, to my sign-up form project! This project offers a seamless and user-friendly experience for registration. Users can effortlessly input their email addresses, with the added convenience of a spellcheck feature to avoid any pesky typos. š ļø Built with ā¢ HTML5 ā¢ CSS3 ā¢ Vanilla Javascript š Thanks I'll be happy to hear any feedback and advice!š¤ Thank you very much!
Community feedback
- @SasaVaticPosted about 1 year ago
Hi Thi Lam, you have done nice work. I will give you some hints in improving your solution which you can use on any project you encounter. First thing I noticed is that page refresh when you submit the form. This is default behavior with forms which can be prevented using javascript. Also I excluded some of javascript code that is not necessary.
let emailError = document.querySelector('#email-error'); let emailField = document.querySelector('#email-field'); let form = document.querySelector('form'); // No need for this emailFiled.value property holds value from the input field // let inputValue = ""; // emailField.addEventListener("input", function(event) { // inputValue = event.target.value; // }); // Prevent form submit so that page does not refresh form.addEventListener('submit', (e) => { e.preventDefault() }) function emailCheck(e){ if (!emailField.value.match((/^[A-Za-z\._\-0-9]*[@][A-Za-z]*[\.][a-z]{2,4}$/))){ emailError.innerHTML = "Valid email required"; } else { emailError.innerHTML = ""; document.querySelector('#sign-up').classList.add('hidden'); document.querySelector('#success-popup').classList.remove('hidden'); // Remove line under since we use emailField.value now // document.querySelector('span').innerHTML = inputValue; document.querySelector('span').innerHTML = emailField.value; } } document.querySelector('#dismiss').addEventListener('click', function(){ document.querySelector('#sign-up').classList.remove('hidden'); document.querySelector('#success-popup').classList.add('hidden'); })
Whole submit logic can be written inside form submit event callback function. But if I modify code to much it wont be so clear. Also I have created JSFiddle example of responsive div which uses max-width CSS property. It is much better to use max-width in this case then width because width is more strict and not responsiveness friendly when it is set up using px units. There are some comments in the example so you can more clearly understand why and what. If you want to learn to make more responsive solutions there is Conquering Responsive Layouts course by Kevin Powell. You can find it on Frontend Mentor. It helped me to improve my html and css code. Happy coding Thi Lam š
Marked as helpful0@zoetlamPosted about 1 year ago@SasaVatic Hi SabijaThor, Thank you so much! Your feedback is incredibly helpful to me, and I will definitely try out your suggestions. I really appreciate it.
1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord