Question

I'd like to implement a functionality, where if the user clicks on a date from the datetime-picker window, its value gets copied into into a div with some class.

Here is my HTML code sample:

<input 
    type="text" 
    class="start_time" 
    id="time2" name="beginn" 
    placeholder="00:00" 
    style="width: 35px"
>       
<div class="start_time_paste">
    Paste here the value from the datetime input!!
</div>

Here is my jQuery code:

jQuery('#time2').datetimepicker({
    datepicker:false,
    format:'H:i',
    step: '30'
});

jQuery('#time2').on('change', function() {
    if(jQuery(this).val() === '0') {

        console.log("läuft");
        var new_start_time = jQuery('.start_time').val();
        jQuery('.start_time_paste').html(new_start_time);

    }    
});

Here is my JSFiddle example: http://jsfiddle.net/C374E/

I don't know what I'm doing wrong :/

Hope someone can help me.

Was it helpful?

Solution

Try to use OnSelectTime event of the datetimepicker. Plugin is stopping execution of the change event.

       jQuery('#time2').datetimepicker
       ({
              datepicker:false,
              format:'H:i',
              step: '30',
              onSelectTime: function(ch)
              {
                     var new_start_time = jQuery('.start_time').val();
                     jQuery('.start_time_paste').html(new_start_time);
              }
          });

Here is the demo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top