I made a choice of days from the calendar using the datepicker. Marking days on the calendar - the date is recorded in the input through zyapatyuyu.
<input type="text" id="altField" value="2015-09-25, 2015-09-26"> Everything is good. It works, but I wanted to see the number of selected days displayed below. With the help of lenght decided to count the number of words, Tipo days.
<div id="result"></div> <script> function dayCount( val ){ return { days: val.match(/\S+/g).length } } var $div = $('#result'); $('#altField').on('input', function(){ var c = dayCount( this.value ); $div.html( "<br>Дней: "+ c.days ); }); </script> But does not work. Suppose if I enter words (dates) from the keyboard or copy them into the input field, I think it is fine, but if the value gets there from the calendar it doesn’t notice it. What to do? :(
change, then you will catch changes. Here I described a little how events work - BOPOHchangeis called when the element loses focus. But you change an element through js? It's a little more difficult with him - change only works when you change an element in the browser. When you change it through js, you have to throw the event yourself. For example:var elem = $('#elem-id'); elem.val('123').change();var elem = $('#elem-id'); elem.val('123').change();- BOPOH