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 ofchange
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
2 Answers
Reset to default 4Since 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();