javascript - Fill Second input with the First input information -


i don't how can this.. example:

i have 2 inputs , when fill first input time , second input add +2 hours.

example:

first input = 10:00

second input automatically put: 12:00

i'd use date object , add 2 hours, has advantage of making 23:00 become 01:00 etc. without hassle.

then it's matter of adding event handler, getting value, creating date object, adding 2 hours, getting hours back, , putting value in other input

var first  = document.getelementbyid('first'); var second = document.getelementbyid('second');  first.addeventlistener('input', function() {      if (this.value.indexof(':') != -1 && this.value.length === 5) {          var date  = new date();         var val   = this.value.split(':');         date.sethours( parseint(val[0], 10) + 2);          var hours = date.gethours();         hours = hours > 9 ? hours : '0' + hours;          second.value = hours + ':' + val[1];     }  }, false); 

fiddle


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -