Click to See Complete Forum and Search --> : refresh page


zuzupus
06-27-2003, 06:10 AM
hi,
below code will calculate diff time between bis and von
as well as between clock and von and the time diff. will be shown on ist field when u try to change bis time,but unfortunately everytime i have to refresh the page to get time in ist field specially to get diff between clock and von

any body knows without using onload function on body i can get updated time in ist field and on the same time when i change time from bis it will show diff. on ist field



<SCRIPT language="JavaScript">
function calculateIst()
{
var timeVon = new Date();
var timeBis = new Date();
var timeIst = new Date();
var time =document.forms["tstest"].elements["von"].value.split(":");
timeVon.setHours(time[0]);
timeVon.setMinutes(time[1]);

var time =document.forms["tstest"].elements["bis"].value.split(":");
timeBis.setHours(time[0]);
timeBis.setMinutes(time[1]);
timeIst.setTime(timeBis.getTime() - timeVon.getTime());
document.forms["tstest"].elements["ist"].value =(timeIst.getHours())-1 + ":" + timeIst.getMinutes();
}

function change()
{

var timeVon = new Date();
var timeClock = new Date();
var timeIst = new Date();
var time =document.forms["tstest"].elements["von"].value.split(":");
timeVon.setHours(time[0]);
timeVon.setMinutes(time[1]);
var time =document.forms["tstest"].elements["clock"].value.split(":");
timeClock.setHours(time[0]);
timeClock.setMinutes(time[1]);
timeIst.setTime(timeClock.getTime() - timeVon.getTime());
document.forms["tstest"].elements["ist"].value =(timeIst.getHours())-1 + ":" + timeIst.getMinutes();
}
</script>

<form name="tstest">
<body onload="change();">
<td nowrap>
<select name="von" size="1">
<option selected value="08:00">08:00</option>
<option value="09:00">09:00</option>
<option value="10:00">10:00</option>
<option value="12:00">12:00</option>
<option value="14:00">14:00</option>
<option value="16:00">16:00</option>
<option value="18:00">18:00</option>
</select>
</td>

<td nowrap>
<input type="text" class="button" size="2" name="clock" >//some function which will update time automatically on ist field
<select name="bis" size="1" onChange="calculateIst()">
<option selected value="08:00">08:00</option>
<option value="09:00">09:00</option>
<option value="10:00">10:00</option>
<option value="12:00">12:00</option>
<option value="14:00">14:00</option>
<option value="16:00">16:00</option>
<option value="18:00">18:00</option>
</select>
</td>
<td><input size="2" type="text" value="0" name="ist" readonly></td>
</form>
</body>
<script language="JavaScript">
function show(){
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()

if (hours<=9)
hours="0"+ hours
if (minutes<=9)
minutes="0"+minutes
document.tstest.clock.value=hours+":"+minutes
setTimeout("show()",1000)
}
show()

</script>

bis von clock ist

zuzupus
06-27-2003, 06:44 AM
if i use onFocus="change" then its workign only problem if somebody let me know how i can get time difference in format like09:09 .now i m getting 9:9 in ist field.

thanks in advance