سؤال

i have a form with about 50 inputfields, lists, checkbox and selectes. I got an submit- and an reset-button. Id like to

  • disable the reset-button if no changes are made,
  • activate if the values are changed by user or javascript and
  • redeactivate if the user removed his changes.

Is there any build-in function in the browser to know if a reset-button make sense?

هل كانت مفيدة؟

المحلول

Why not just deactivate/disabled the reset button by default on the page and use jquery .change to listen for changes and activate/enable the button.

You can do something like this: http://jsfiddle.net/gNS8L/

If an input fields value has changed (note: you can leave out the part with the originalvalue, where it checks if it has changed back to original) you take away the disabled attribute from the button. If the button is pressed it gets disabled again, you can also disable it if the value changes back to original.

Edit: so you do this to reset it on original value: http://jsfiddle.net/gNS8L/1/

نصائح أخرى

Use the jquery dirty form plugin, it is exactly made for this

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top