Click to See Complete Forum and Search --> : Dynamic Time Form


crawford96
07-25-2008, 09:09 AM
Hello,

It's been awhile since I have used my Javascript skills and was hoping someone might be able to help me find a solution to my need.

I am looking to build a form that once you enter a time in one field, it automatically populates another field with a corelated time.

Example: User enters a time of 13:00 in the first field. The second field is set to disapy the entered time + 30mins and thus outputs a time of 13:30.

Is this possible?

Like I said, it's been awhile since I have coded in javascript so I apologize if this is something easy or not doable.

Thanks

Ayşe
07-25-2008, 10:59 AM
<script type="text/javascript">

function f(){
var el=document.getElementById('inp1');
var s=el.value.split(":");
var d = new Date();
d.setHours(s[0]*1, s[1]*1 + 30);
var el2=document.getElementById('inp2');
var h = (d.getHours()<10) ? "0"+ d.getHours() : d.getHours();
var m = (d.getMinutes()<10) ? "0"+ d.getMinutes() : d.getMinutes() ;
el2.value = h +":"+m;
}
</script>
</head>
<body>
Date 1 :<input type="text" id="inp1" onchange="f()"><br>
Date 2 : <input type="text" id="inp2" >