jquery - count words in input field from datepicker -


i chose calendar days using datepicker. marking days on calendar - date written in input, separated commas this:

<input type="text" id="altfield" value="2015-09-25, 2015-09-26"> 

it works, want display number of selected days. lenght decided count number of words in input 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>days: "+ c.days   ); }); </script> 

but not working. if input words byth keyboard or copy paste them input field script counts them, if values comes calendar script doesnt count them. shoul change?


Comments