0

I am use timepicker jquery. I have to Text field one is From and second is To. so when time From select auto update time TO field so

$('#onselectExample').timepicker();
$('#onselectExample').on('changeTime', function() {
    $('#onselectTarget').text($(this).val());
});
Ashish Mehta
  • 7,226
  • 4
  • 25
  • 52

1 Answers1

1

Do you want to change #onselectTarget when #onselectExample changes? It can be achieved as follows:

$('#onselectExample').timepicker({
    onSelect: function(selectedDateTime){
        $('#onselectTarget').text(selectedDateTime);
    }
});

And in case you want to add 30 minutes to the selected Time you could write an extra fundtion:

        $(function(){
            $('#onselectExample').timepicker({
                onSelect: function(selectedDateTime){
                    console.log(selectedDateTime);
                    $('#onselectTarget').text(add30Min(selectedDateTime));
                }
            });
        });
        function add30Min(oldTime){
            var time = oldTime.split(":"); //split hours an minutes
            var hours = time[0]; // get hours
            var minutes = time[1]; // get minutes
            if (+minutes >= 30){ // when minutes over 30
                hours = (+hours+1)%24; // add an hour and convert 24 to 0
            }
            minutes = (+minutes + 30)%60; // add 30 minutes and convert 61 to 1
            return $.datepicker.formatTime('hh:mm',{ // use formatTime to return formatted Time
                'hour':hours,
                'minute':minutes
            });
        }
Jen-Ya
  • 328
  • 4
  • 14
  • I am USe Like This [jquery] $("#time_from, #time_to").timePicker(); $("#time_from").change(function() { var selectedDateTime = $('#time_from').val(); Problem is that when i focus on time from text field show time is not disable – Ashish Mehta Oct 12 '12 at 11:00
  • Sorry, but it is impossible to understand what you want to achieve. You might want to provide the full source code. – Jen-Ya Oct 12 '12 at 11:51