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

Base Apparel email form using match()

Phil 185

@PhilJG

Desktop design screenshot for the Base Apparel coming soon page coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


I had trouble in these three areas:

When the button is pressed the valid or invalid notice will come up. However it will not change if the text is change unless the page is refreshed. It seems that the function can only be called once?

The blue border on the input box. Apparently when adjusted in :active or :focus states it does not change. How do I get rid of it?

I`m having trouble with github pages. Whenever the button is pressed it just takes to a 404 page. That does not help demonstrate the work I did. How do I adjust this?

Community feedback

@GHamza-Dev

Posted

Hi Phil 👋

First, keep it up!!! I really liked your solution.

  • For the first issue it happens because you grabbed the input value just once and what happened is the function called each time you click the button but it uses the old input value.

To fix this problem you should grab the input value each time you want to make a check

An appropriate solution would be like:

//....
const email = document.getElementById("email"); 
// Notice that I selected the element and kept it (without getting the value from it).
//....
//......
//....
let inputValue = " ";  // simple declaration

function validation() {

        inputValue = email.value; // I get the value of the input each time I call the function

        if (inputValue.match(pattern))  // Or simply: if (email.value.match(pattern)) 
        {
            form.classList.add("valid");
            form.classList.remove("invalid");
            //.....
            //.......... the rest of your code 

Thus should work 100%!! and if you need more clarification do not hesitate to ask for it.

Final tip: There is also a way of validating inputs using CSS you may want to learn about it If so search for validity pseudo-selectors (:valid & :invalid pseudo-selectors)

HAPPY CODDING!!

Marked as helpful

0
Phil 185

@PhilJG

Posted

Thank you Gassai for all your feedback.

Using the blank declaration worked like a charm! This is great because I was having this issue on a personal project as well :)

I looked up validity pseudo-selectors and it works also when the correct or incorrect is format is entered. However I still get a blue border around the input when it is clicked?

Not sure how to adjust that but when I do I think this will be good to go.

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