开发者

Check if form field changes

I have some form fields like <input>, <textarea>, <dropdown> etc.

If a user make a change in any form field it should be prompted at once that field is changed.

I applied different events like onKeyPress (did not work for backspace key), onChange (works when lose focus).

Is its not possible开发者_如何学运维 in simple/plain JavaScript then I want to know it in Dojo.


see stack question: Detect all changes to a <input type="text"> (immediately) using JQuery

while the accepted answer is using jquery setInterval works just fine with javascript. just use GetElementByID or GetElementsByTagName to get your input fields and then just check their values against themselves.


There is no HTML "dropdown" element, you probably meant a select.

For some controls you can compare a control's current value to its defaultValue to see if it's changed, pick whatever event suits for the control. For select, onchange is best and compare to the previously selected option (if there was one). Input and textarea you can likely use keyup. Radio buttons and checkboxes click and compare with the one that was checked previously (if there was one).


Through javascript attach event onFocus on input field. Onfocus setTimeout() and make it recursive. If any content will change, it will notify. In my case it works; even I did another task from it. I save existing input field value on page load. e.g it was abc on page load. User change it to abcd then there will be a message for unsave changes. But when user delete d and make it abc again then message will disappear, means there are no unsaved changes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜