Programmatically manipulating DOM element value doesn't fire onchange event

后端 未结 2 1895
温柔的废话
温柔的废话 2021-01-28 11:56

I\'ve got a hidden form field, and when a button gets pressed the value of the hidden field is changed. Now, I\'ve added an observer to the hidden field, listening for changes t

2条回答
  •  梦如初夏
    2021-01-28 12:39

    You need event.simulate.js

    Fire the event..

    button.observe('click', function(event) {
      hiddenField.setValue(someValue);
      hiddenField.simulate('change');
    });
    

    And then observe it:

    hiddenField.observe('change', function(event) {
      alert('It works!');
    });
    

提交回复
热议问题