javascript - onChange event not firing when input changed dynamically - Stack Overflow

On my form, I have a DropDown, when a value is selected, I fire some JavaScript that populates some vis

On my form, I have a DropDown, when a value is selected, I fire some JavaScript that populates some visible <input type="text" /> fields (under neath the drop down).

The problem is, I also want to run some JavaScript function whenever the value of one of these inputs changes, I want this function to run even if the text input is changed by the drop down selection.

Here is my current code:

jQuery(document).ready(function() {
    $('#mainPane').on('change', '#formElementFromEmail', function(event){
        var collectFromDropDown = $('#formElementFromEmail');
        persistHiddenInputForCollectFromValue();
    });
});

I suspect the change event is not being fired because no one has manually changed the value of the field in question. How can I overe this?

On my form, I have a DropDown, when a value is selected, I fire some JavaScript that populates some visible <input type="text" /> fields (under neath the drop down).

The problem is, I also want to run some JavaScript function whenever the value of one of these inputs changes, I want this function to run even if the text input is changed by the drop down selection.

Here is my current code:

jQuery(document).ready(function() {
    $('#mainPane').on('change', '#formElementFromEmail', function(event){
        var collectFromDropDown = $('#formElementFromEmail');
        persistHiddenInputForCollectFromValue();
    });
});

I suspect the change event is not being fired because no one has manually changed the value of the field in question. How can I overe this?

Share Improve this question edited Feb 19, 2014 at 17:24 J86 asked Feb 19, 2014 at 17:19 J86J86 15.3k50 gold badges145 silver badges249 bronze badges 3
  • Try blur event instead of change on input field. – Latheesan Commented Feb 19, 2014 at 17:21
  • you can use keyup,also your question is not clear – A.T. Commented Feb 19, 2014 at 17:21
  • I hope it is clearer now. I tried blue .. and got same thing, not firing. :( – J86 Commented Feb 19, 2014 at 17:24
Add a ment  | 

2 Answers 2

Reset to default 4

Since you're using jQuery, you can trigger the event:

$('#mainPane').trigger('change');

you can simulate change event by

var element = document.getElementById('formElementFromEmail');
element.onchange();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742398376a4436407.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信