0

I made simple date picker using JavaScript and jQuery. After choosing date it is shown in input box. This input box is not launching change event, probably because it was changed using JavaScript. Is there any way to launch this event, or to make custom one?

5
  • Did you use a datepicker plugin (such as the one from jQuery UI) or implement your own? Feb 13, 2012 at 9:09
  • it should be launch the onchange event. Please post ur code
    – Yorgo
    Feb 13, 2012 at 9:09
  • im changing value using $( "#" + calName + "_date" ).val( cal.actualdate + ". " + (cal.month+1) + ". " + cal.year ); It is working after I added $( "#" + calName + "_date" ).change();(Thx Kane Black) Feb 13, 2012 at 9:17
  • bind the onchange functionality with live function api.jquery.com/live and it would be helpful if u show some code
    – run
    Feb 13, 2012 at 9:19
  • possible duplicate of jquery invoke .change without user action but by .val change Feb 13, 2012 at 10:56

4 Answers 4

2

Run this code after you assign new value:

$('input').change();
2
  • 1
    Would be better to fire the event on the specific input, rather than ALL inputs.
    – SpaceBison
    Feb 13, 2012 at 9:11
  • @SpaceBison, it was just a generic answer. I assumed that Uriel_SVK knows how to assign change event to specific input field.
    – Kane Cohen
    Feb 13, 2012 at 10:29
1

.change just points to the .on function inside jquery, so it's better to use the .on directly.

$('#inputID').on('change', function() {
});
0
$("input#yourInputId").change();

or

$("input#yourInputId").trigger("change");

Should do the trick. Replace the #yourInputId with an id that represents the ID="abc" part of your HTML for the textbox

  • Be aware of potential browser irregularities or lack of support for change events - behaviour may vary, particularly in older browsers.
1
  • jQuery normalize the change-behavior for IE6> Feb 13, 2012 at 9:21
0

There is a change and an input event. The first fires after an input changed and lost focus. The latter fires immediately when the input changes. However there are no events that fire after programatically changing an input.

If you have control over the code that changes your inputs you can of course trigger the events manually like described in the other answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.