Ticket #4778 (closed enhancement: wontfix)
Adding a change event on a hidden field
| Reported by: | nabab | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4 |
| Component: | core | Version: | 1.3.2 |
| Keywords: | Cc: | thomas.nabet@… | |
| Blocking: | Blocked by: |
Description
Hi,
I would like to be able to trigger a function when the value of a hidden field is changed through val() - and I want this event to be attached to the field itself, not to the val() action. As events are only users' triggered a hidden field doesn't trigger onchange natively. I have seen a lot of implementations using various plug-ins for mutation events, but was not very happy about them - they're heavy and I got some errors. Therefore I have added a line at the very end of the val() function: if(o.nodeName(this,"select")){ ... } else{ this.value=K; Here's my line: if(this.type=='hidden'){$(this).change()} } ...
This works fine in IE6, FF and Chrome - haven't tested on other browser.
The code I have added in the val() function is, I think, the most efficient way for being able to trigger the change function on any hidden field. However, as I love jQuery and hate to have my own twisted script instead of the standard, I wonder if people think it could be implemented in the core or if someone would have a better global solution to that problem...
Thanks!
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

A programmatic change to a field is not considered a change for the purposes of event dispatching. (Trust me, it would break a lot of stuff if it were.) You will just need to raise an event yourself if you want one after a programmatic value change to a form field.