How to call a js function onSelect event of datepicker jquery?
Asked Answered
T

3

11

Please anyone help me.. I have a js function

function updateAb(param){ some manipulation }

And i am calling a datepicker jquery onselect event like..

$( ".datepicker").datepicker({onSelect: function(dateText, inst) { ... }});

I want to call the js function in select, how to do that? My objective is to get the value onselect of date from the datepicker and setting the attribute value in input field. Can anyone help me???

Tav answered 1/6, 2012 at 6:4 Comment(0)
B
31

Here goes ur code

$('.datepicker').datepicker({
    dateFormat: 'dd-mm-yy',
    numberOfMonths: 1,
    onSelect: function(selected,evnt) {
         updateAb(selected);
    }
});

function updateAb(value){     
    $('#yourInputID').val(value);    
}
Bigeye answered 1/6, 2012 at 6:8 Comment(1)
@JuanMendes Yeah you are right, i was not clear with my question, but i wanted what Kabilan posted here. Thanks to both of you...Tav
I
5
$( ".datepicker").datepicker({
    onSelect: function(dateText, inst) { 
        updateAb(dateText);
    }
});

Even more simply, if you do want the dateText and inst parameters to be passed to updateAb

$( ".datepicker").datepicker({onSelect: updateAb});
Idiosyncrasy answered 1/6, 2012 at 6:7 Comment(0)
G
3
$( ".datepicker").datepicker({
       onSelect: function(dateText, inst) {
          updateAb(dateText, inst);
       }
});

In short

$( ".datepicker").datepicker({
    onSelect: updateAb
});
Geraldo answered 1/6, 2012 at 6:6 Comment(4)
Are you updating copying my answer? :pIdiosyncrasy
@JuanMendes no mate, its not my habit,it happen in parallalGeraldo
I didn't think you were actually doing it, just that I kept seeing your updates immediately after my updatesIdiosyncrasy
@JuanMendes so what should I do, mate?Geraldo

© 2022 - 2024 — McMap. All rights reserved.