Hi all!
This new forum its great! :)
Congratulations !!!
My answer: why this my code not working?
Nothing error but not work the difference.... : - <html>
-
-
<head>
-
<script language="JavaScript">
-
<!--
-
-
-
var difference = function(leftHour, rightHour){
-
if(!leftHour || !rightHour)
-
return null;
-
spt = leftHour.split(":");
-
var totLeft = parseInt(spt[0]) * 60 + parseInt(spt[1]);
-
spt = rightHour.split(":");
-
var totRight = parseInt(spt[0]) * 60 + parseInt(spt[1]);
-
return totLeft - totRight;
-
}
-
-
var diff1 = difference(myForm.F.value, myForm.E.value);
-
var diff2 = difference(myForm.D.value, myForm.A.value);
-
var diff3 = difference(myForm.G.value, myForm.F.value);
-
var diff4 = difference(myForm.H.value, myForm.G.value);
-
var diff5 = difference(myForm.H.value, myForm.A.value);
-
-
// -->
-
</script>
-
-
</head>
-
<body>
-
-
<form name="myForm">
-
-
<input type="text" name="A" size="20">
-
<input type="text" name="B" size="20">
-
<input type="text" name="C" size="20">
-
<input type="text" name="D" size="20">
-
<input type="text" name="E" size="20">
-
<input type="text" name="F" size="20">
-
<input type="text" name="G" size="20">
-
<input type="text" name="H" size="20">
-
-
<input type="text" name="RISULTATO1" size="20">
-
<input type="text" name="RISULTATO2" size="20">
-
<input type="text" name="RISULTATO3" size="20">
-
<input type="text" name="RISULTATO4" size="20">
-
<input type="text" name="RISULTATO5" size="20">
-
-
-
</form>
-
-
</body>
-
-
</html>
9 2493
New code: -
<html>
-
-
<head>
-
<script language="JavaScript">
-
<!--
-
-
-
var difference = function(leftHour, rightHour){
-
if(!leftHour || !rightHour)
-
return null;
-
spt = leftHour.split(":");
-
var totLeft = parseInt(spt[0]) * 60 + parseInt(spt[1]);
-
spt = rightHour.split(":");
-
var totRight = parseInt(spt[0]) * 60 + parseInt(spt[1]);
-
return totLeft - totRight;
-
}
-
-
function Calcola()
-
{
-
-
var diff1 = difference(myForm.F.value, myForm.E.value);
-
var diff2 = difference(myForm.D.value, myForm.A.value);
-
var diff3 = difference(myForm.G.value, myForm.F.value);
-
var diff4 = difference(myForm.H.value, myForm.G.value);
-
var diff5 = difference(myForm.H.value, myForm.A.value);
-
-
myForm.RISULTATO1.value = diff1
-
myForm.RISULTATO2.value = diff2
-
myForm.RISULTATO3.value = diff3
-
myForm.RISULTATO4.value = diff4
-
myForm.RISULTATO5.value = diff5
-
-
-
}
-
// -->
-
</script>
-
-
</head>
-
<body>
-
-
<form name="myForm">
-
-
A<input type="text" name="A" size="20">
-
B<input type="text" name="B" size="20">
-
C<input type="text" name="C" size="20">
-
D<input type="text" name="D" size="20">
-
E<input type="text" name="E" size="20">
-
F<input type="text" name="F" size="20">
-
G<input type="text" name="G" size="20">
-
H<input type="text" name="H" size="20">
-
-
<br><br>
-
-
F-E<input type="text" name="RISULTATO1" size="20" onClick="Calcola()">
-
D-A<input type="text" name="RISULTATO2" size="20" onClick="Calcola()">
-
G-F<input type="text" name="RISULTATO3" size="20" onClick="Calcola()">
-
H-G<input type="text" name="RISULTATO4" size="20" onClick="Calcola()">
-
H-A<input type="text" name="RISULTATO5" size="20" onClick="Calcola()">
-
-
-
</form>
-
-
</body>
-
-
</html>
-
That's an improvement. In place of myform, use document.myform.
You may also want to use one button only to call the function rather than onclick of each text box.
many thanks x your reply.
this script now working but I need check that: - hour field B ever > hour field A
- hour field C ever > hour field B
- hour field D ever > hour field C
- hour field E ever > hour field D
- hour field F ever > hour field E
- hour field G ever > hour field F
- hour field H ever > hour field G
Can you help me ?
My script: -
<html>
-
-
<head>
-
<script language="JavaScript">
-
<!--
-
-
-
var difference = function(leftHour, rightHour){
-
if(!leftHour || !rightHour)
-
return 0;
-
spt = leftHour.split(":");
-
var totLeft = parseInt(spt[0],10) * 60 + parseInt(spt[1],10);
-
spt = rightHour.split(":");
-
var totRight = parseInt(spt[0],10) * 60 + parseInt(spt[1],10);
-
-
if (totLeft < totRight) {
-
-
alert("ko");
-
return 0;
-
-
}
-
-
return totLeft - totRight;
-
}
-
-
function Calcola()
-
{
-
-
var diff1 = difference(document.myForm.F.value, document.myForm.E.value);
-
var diff2 = difference(document.myForm.D.value, document.myForm.A.value);
-
var diff3 = difference(document.myForm.G.value, document.myForm.F.value);
-
var diff4 = difference(document.myForm.H.value, document.myForm.G.value);
-
var diff5 = difference(document.myForm.H.value, document.myForm.A.value);
-
-
document.myForm.RISULTATO1.value = diff1
-
document.myForm.RISULTATO2.value = diff2
-
document.myForm.RISULTATO3.value = diff3
-
document.myForm.RISULTATO4.value = diff4
-
document.myForm.RISULTATO5.value = diff5
-
-
-
}
-
// -->
-
</script>
-
-
</head>
-
<body>
-
-
<form name="myForm">
-
-
A<input type="text" name="A" size="20" onkeyup="Calcola()">
-
B<input type="text" name="B" size="20" onkeyup="Calcola()">
-
C<input type="text" name="C" size="20" onkeyup="Calcola()">
-
D<input type="text" name="D" size="20" onkeyup="Calcola()">
-
E<input type="text" name="E" size="20" onkeyup="Calcola()">
-
F<input type="text" name="F" size="20" onkeyup="Calcola()">
-
G<input type="text" name="G" size="20" onkeyup="Calcola()">
-
H<input type="text" name="H" size="20" onkeyup="Calcola()">
-
-
<br><br>
-
-
F-E<input type="text" name="RISULTATO1" size="20" value="0" readonly>
-
D-A<input type="text" name="RISULTATO2" size="20" value="0" readonly>
-
G-F<input type="text" name="RISULTATO3" size="20" value="0" readonly>
-
H-G<input type="text" name="RISULTATO4" size="20" value="0" readonly>
-
H-A<input type="text" name="RISULTATO5" size="20" value="0" readonly>
-
-
-
</form>
-
-
</body>
-
-
</html>
-
-
Do you want to make this generic (i.e. for any number of fields) or will it always be 8 fields from A to H?
Try this... working... :) -
<script>
-
-
function isTime(str) {
-
str="0"+str+":0"
-
spz = str.replace("\.",":").split(":"); // accetta anche il . come separatore
-
hh = parseInt(spz[0],10)
-
mm = parseInt(spz[1],10)
-
if ((hh == 24 && mm == 0) || (hh < 24 && mm < 60))
-
return (hh*60+mm);
-
return false;
-
}
-
-
function Calcola() {
-
for(var i=1; i<=7; i++) {
-
cx = ("ABCDEFGH").substr(i-1,1);
-
cy = ("ABCDEFGH").substr(i,1);
-
x = isTime(document.myForm.elements(cx).value);
-
y = isTime(document.myForm.elements(cy).value);
-
if(x && y) {
-
document.myForm.elements(cy).style.background='white';
-
if(y>x) {
-
document.myForm.elements("RISULTATO"+i).value = (y-x);
-
} else {
-
document.myForm.elements(cy).style.background = 'orange';
-
}
-
}
-
}
-
}
-
</script>
-
-
<form name="myForm">
-
-
A<input type="text" name="A" size="5" onkeyup="Calcola()">
-
B<input type="text" name="B" size="5" onkeyup="Calcola()">
-
C<input type="text" name="C" size="5" onkeyup="Calcola()">
-
D<input type="text" name="D" size="5" onkeyup="Calcola()">
-
E<input type="text" name="E" size="5" onkeyup="Calcola()">
-
F<input type="text" name="F" size="5" onkeyup="Calcola()">
-
G<input type="text" name="G" size="5" onkeyup="Calcola()">
-
H<input type="text" name="H" size="5" onkeyup="Calcola()">
-
-
<br><br>
-
-
B-A<input type="text" name="RISULTATO1" size="5" value="0" readonly>
-
C-B<input type="text" name="RISULTATO2" size="5" value="0" readonly>
-
D-C<input type="text" name="RISULTATO3" size="5" value="0" readonly>
-
E-D<input type="text" name="RISULTATO4" size="5" value="0" readonly>
-
F-E<input type="text" name="RISULTATO5" size="5" value="0" readonly>
-
G-F<input type="text" name="RISULTATO6" size="5" value="0" readonly>
-
H-G<input type="text" name="RISULTATO7" size="5" value="0" readonly>
-
-
</form>
-
-
Nice - thanks for posting!
Sorry for nit-picking; I'm bored.
Your scripts should be done like so: -
<script type="text/javascript">
-
-
[...]
-
-
</script>
-
:D
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
2 posts
views
Thread by Marcus |
last post: by
|
reply
views
Thread by GerritM |
last post: by
|
5 posts
views
Thread by Paul |
last post: by
|
26 posts
views
Thread by Frank |
last post: by
|
23 posts
views
Thread by Rudolf Bargholz |
last post: by
|
6 posts
views
Thread by Sameer |
last post: by
|
2 posts
views
Thread by John |
last post: by
|
1 post
views
Thread by mimmo |
last post: by
|
11 posts
views
Thread by stax |
last post: by
| | | | | | | | | | |