Rene
Rene

Reputation: 13567

How can i set a variable value into an input value

Is it possible to set an input value based on an inserted variable in jquery?

i would like to set the input of an input field into another input field. example:

<input type="timepicker" name="duur" value="" placeholder="Duur" id="endduur"/>
                <input type="timepicker" name="mytime" value="" placeholder="endtime" id="endtimestatusduur"/>

i would like to get the value of the input id "endduur" and set the same value into the input field with the id "endtimestatusduur" i think it needs to be something like this:

endduur = $("#endduur").val();
      function endtimestatus() {
    var arr = [];
    $.each(arguments, function() {
        $.each(this.split(':'), function(i) {
            arr[i] = arr[i] ? arr[i] + (+this) : +this;
        });
    })

    return arr.map(function(n) {
        return n < 10 ? '0'+n : n;
    }).join(':');
}
      endtimestatus = endtimestatus(starttimestatus, endduur),
      endtimestatusduur = $("#endtimestatusduur").val(endtimestatus);

Upvotes: 0

Views: 74

Answers (1)

Kiran
Kiran

Reputation: 20313

Use change method. Try this:

$(document).ready(function(){
    $('#endduur').datepicker({
weekStart: 1,
dateFormat: 'dd/mm/yy',
        change: function(time){
         $("#endtimestatusduur").val($(this).val());
    }
});
});

For more details: http://timepicker.co/options/

DEMO

Upvotes: 1

Related Questions