Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Newsletter Sign Up with Success Message

matt2282 310

@matt2282

Desktop design screenshot for the Newsletter sign-up form with success message coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


What challenges did you encounter, and how did you overcome them?

I had trouble creating the custom error message. I figured out that if I set the type to 'email' in the html form input it would handle the input validation for an email. However, it took some time to figure out how to combine this with JavaScript. By using the "invalid" argument in an event listener for the form input allowed me to do this.

Community feedback

MikDra1 6,010

@MikDra1

Posted

Nice one

If you are cerious there is also a CSS property that we can use to check wether the input is in valid or invalid state and here is how it works

/* Style for invalid input fields */
input:invalid {
    border: 2px solid red;  /* Red border for invalid input */
    background-color: #ffe6e6;  /* Light red background */
    color: #a94442;  /* Darker red text */
}

input:invalid:focus {
    outline: none;
    box-shadow: 0 0 5px red;  /* Red shadow when focused */
}

textarea:invalid, select:invalid {
    border: 2px solid red;
    background-color: #ffe6e6;
    color: #a94442;
}

Explanation:

  • input:invalid: This targets any <input> element that is invalid according to its validation rules (e.g., type="email" without a valid email format).

  • background-color and border: Provide visual feedback with a red border and a light red background.

  • input:invalid:focus: Adds a red shadow when the invalid input is focused, making it stand out.

Marked as helpful

1

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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