how to use one javascript function for multiple input fields
For example it will show Infinity for division by 0 or NaN if numbers get to big. 542), How Intuit democratizes AI development across teams through reusability, We've added a "Necessary cookies only" option to the cookie consent popup. state here we are declaring the state using useState hook, user represents the object we inserted into useState, setUser is going to be used to update the state. Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. In JavaScript, a debounce function makes sure that your code is only triggered once per user input. Your point on the use of js for validation is well taken. A-143, 9th Floor, Sovereign Corporate Tower, We use cookies to ensure you have the best browsing experience on our website. are patent descriptions/images in public domain? Thanks for contributing an answer to Stack Overflow! To learn more, see our tips on writing great answers. Making statements based on opinion; back them up with references or personal experience. In the following example, we have 2 input fields and a button element. How to validate if input in input field has base 32 encoded string using express-validator ? How to display a PDF as an image in React app using URL? How can I recognize one? How can I improve my code? Find centralized, trusted content and collaborate around the technologies you use most. Because the form name props match the state property keys, the firstName input will set the firstName state and the lastName input will separately set the lastName state. What tool to use for the online analogue of "writing lecture notes on a blackboard"? How to increase the number of CPU in my computer? ).value = val; to e.target.value = val; and you'll be able to use the same function for both inputs. If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
how to use one javascript function for multiple input fields
Want to join the discussion?Feel free to contribute!