javascript - Fill Duration when user inputs time -


i'm trying auto fill duration in live form when user inputs data. formula followed: time duration = out – in .

not sure how data user inputs in live form(before hit submit) , display in duration location in form. below example of user imputing in , out data , result being duration should displayed before submit button clicked. ex:

      in:01:00:00      out:00:01:00  duration:00:99:00 

	var template;  		var numofsegments = 1;    		window.addeventlistener('load', function() {  			template = document.queryselector("#wrapper").innerhtml;  			document.queryselector("#more_fields").addeventlistener("click", function(e) {  				e.preventdefault(); // tell browser not send form  				document.getelementbyid('wrapper').insertadjacenthtml('beforeend', template); // add next segment  				numofsegments = document.queryselectorall("div.segment").length;  				document.queryselector("div.segment:last-of-type > label").innerhtml = "day " + (numofsegments) + ":"; //updates segment #  			});  		})      		function deleteme() {  			if (numofsegments > 1) {  				var btn = document.queryselector("#wrapper > div.segment:last-of-type");  				btn.remove();  				event.preventdefault();  			}  		}    		function addnumseg() {  			var elem = document.getelementbyid("segments_num");  			elem.value = ++numofsegments;  		}    		function subtractnumseg() {  			var elem = document.getelementbyid("segments_num");  			if (numofsegments > 1) {  				elem.value = --numofsegments;  			}  		}
			<div id="room_fileds">  				<div class="content" id="wrapper">  					<div class="segment">  						<label id="seg[]" style="margin:0 0 10px 60px;display: inline;">day 1:</label>  						<div class="form-group" style="display: inline;">  							<label id=seg-in[] style="margin:0 0 10px 35px;display: inline;">in:</label>  							<input class="form-control seg_in" id="seg-in" placeholder="hh:mm:ss;ff (df)" type="text" pattern="([01]\d|2[0-3]):([0-5]\d):([0-5]\d);([0-5]\d)" style="margin:0 0 10px 5px;width:15%;display: inline;">  						</div>  						<div class="form-group" style="display: inline;">  							<label id=seg-out[] style="margin:0 0 10px 35px;display: inline;">out:</label>  							<input class="form-control seg_out" id="seg-out" type="text" placeholder="hh:mm:ss;ff (df)" pattern="([01]\d|2[0-3]):([0-5]\d):([0-5]\d);([0-5]\d)" style="margin:0 0 10px 5px;width:15%;display: inline;">  						</div>    						<div class="form-group" style="display: inline;">  							<label id="seg-dur[]" style="margin:0 0 10px 35px;display: inline;">duration:</label>  							<input class="form-control seg_dur" id="seg-dur" type="text" placeholder="hh:mm:ss;ff (df)" pattern="([01]\d|2[0-3]):([0-5]\d):([0-5]\d);([0-5]\d)" style="margin:0 0 10px 5px;width:15%;display:inline" readonly>  						</div>  					</div>  				</div>  			</div>    			<div style="text-align:right;">  				<div style="display:inline;text-align: right;">  					<button onclick="deleteme(); subtractnumseg();" type="button" style="height: 25px;width:14px;" id="less_fields">-</button>  				</div>    				<div style="display:inline;text-align: right;">  					<button onclick="addnumseg();" type="button" style="height: 25px;width:14px;" id="more_fields">+</button>  				</div>  			</div>    			<br><br>  			<button type="button" class="btn btn-default" id="formsubmit">submit</button>


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -