how to use one javascript function for multiple input fields
You could test the result for NaN or Infinity and show a proper message to the user: Event though it's a very simply example, add these two things in your header: You're using form elements that are not descendants of a form element, nor do you link them to a form using the form-attribute. The user data which is now stored in state can be passed down to different components as needed. How to toggle a boolean using JavaScript ? Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"? In order to update that state, we use the change events evt.target.name field. false, to prevent the form from being submitted: The function can be called when the form is submitted: JavaScript is often used to validate numeric input: HTML form validation can be performed automatically by the browser: If a form field (fname) is empty, the required attribute prevents this form from being Place all input's into one block and call jQuery as: $("#maindiv > input").prop("disabled", true); Share. Server side validation is performed by a web server, after input has been sent to the How to validate if input in input field is divisible by or multiple of a number using express-validator ? By using our site, you Thanks for contributing an answer to Stack Overflow! as in example? Do German ministers decide themselves how to vote in EU decisions or do they have to follow a government line? How to create a Color-Box App using ReactJS? There are several date inputs scattered through the form, each one set up the same, other than the input names (day1 vs day 1 vs day 3, etc). Are there conventions to indicate a new item in a list? If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: