I’d like to track changes in inputs in a form via javascript. My intent is (but not limited) to
- enable ‘save’ button only when something has changed
- alert if the user wants to close the page and something is not saved
Ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Loop through all the input elements, and put an
onchangehandler on each. When that fires, set a flag which lets you know the form has changed. A basic version of that would be very easy to set up, but wouldn’t be smart enough to recognize if someone changed an input from ‘a’ to ‘b’ and then back to ‘a’. If it were important to catch that case, then it’d still be possible, but would take a bit more work.Here’s a basic example in jQuery: