// css part
//the class “error_message” that was added in js will be styled in the css file.
.error{
border: 2px solid var(- -Red);
}
.error_message : :after {
content: “Kindly fill in valid card details “;
color: var(- -Red);
margin-top: .2rem;
}
16
else{
input.classList.remove(“error “);
Input.parentElement.classList.remove(“error_message”)
}
})
}
1
16
//target the “id” of the input fields. Which is “input” .
Input.forEach(input => {
const value = input.value.trim();
If(!input.value){
Input.classList.add(error)
Input.parentElement.classList.add(“error_message”)
}
1
9
How to display error message when your input field is empty using js and css.
.you can create a function to display errors.
eg.
Function displayError (e) {
e.preventDefault();
//iterate over all input field using for each method
1
17
.Attached h#the class using the “textContent” property.
.Also target the span or areas you going to display the text gotten from the input field and attach to the “.value” property.
eg
cardNumber.text content = document.querySelector(“.display-number”).value;
};
29
How to display your input on real time using JavaScript.
.You can create a function to display input in real time
eg
Function displayInRealtime (){
.Target all your input field using “class” or “id”
eg
const cardNumber = document.getElementById(“number”);
1
30
