0

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);
2
  • 1
    #endtimestatusduur doesn't exist in your HTML, do you mean #endtimestatus? Commented Mar 27, 2014 at 11:23
  • Srry i meant #entimestatusduur i've edited the question Commented Mar 27, 2014 at 11:25

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

10 Comments

That doesnt set an value into the entimestatusduur:(
@Rene: Updated answer. Please check.
@Rene: Is it helpful?
It is helpful but i have a timepicker on the first input field but then it wont set the value into the other input field. Only when i type in the first input field. How can i make this possible
@Rene: Check the latest one bro :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.