form.addEventListener('submit',(event)=>{
event.preventDefault()
const input=[nameinput,desc,number];
if(nameinput.value.trim() && desc.value.trim() && number.value.trim()){
let obj = {
name: nameinput.value,
desc: desc.value,
price: number.value
}
axios.post("http://localhost:3000/Pulse", obj)
.then(res => {
window.location = "./index.html"
})
}
})
How can I add form validation with javascript? required.
To add form validation in JavaScript, you can check if the input values meet certain criteria before submitting the form. For example, you can check if the fields are not empty.
How can I add form validation with javascript? required.
To add form validation in JavaScript, you can check if the input values meet certain criteria before submitting the form. For example, you can check if the fields are not empty.
2
Answers
Your question isn’t well structured and I don’t understand what validation type you’re asking for, but if you want to check if the input fields meet your criteria you can simply add an ‘input’ event listener to your input field.
That way, you can check if the field is valid on every user input.
The code below checks if the user’s input is below a certain number of characters.
You can simply disable the submit button if input field criteria isn’t met.