Search code examples
javascriptjquerydatepickertwitter-bootstrap-2

Javascript alert more than one


for some reason I'm getting alert more than once. Here is my code:

    $('.input-append.date').datepicker({
    format: "MM yyyy",
    startView: 1,
    minViewMode: 1,
    autoclose: true
    }); 


$('.input-append.date').on('change', function() {
    var one = $("#month").val(); 
   alert(one); 
   return false;
});


<div class="input-append date">
    <input id="month" type="text" placeholder="Select Month" class="span8"><span class="add-on"><i class="icon-th"></i></span>
 </div> 

Why is that? Here is a demo : http://jsfiddle.net/HFuDg/168/

Please help and thanks in advance.


Solution

  • Not sure why change fires multiple times but if you bind to hide, that fires once.

    $('.input-append.date').on('hide', function() {
       var one = $("#month").val(); 
       alert(one);
       return false;
    });