Perform control schedule
Collapse
X
-
How to change this ?
var hours = parseInt(vals[0]);
var mins = parseInt(vals[1]);Leave a comment:
-
I've made some quick changes without testing to give you an idea:
[code=javascript]function updateTime(txtO bj)
{
if (window.opener == null) return;
var re = /^([01]\d|2[0-3]):[0-5]\d$/;
if (txtObj.value.l ength >= 5 && !txtObj.value.m atch(re))
{
alert("Inserire l'orario nel formato 'hh:mm'.");
txtObj.focus();
}
var frmObj = txtObj.form;
var elems = frmObj.elements ;
var result = "";
var destObj = window.opener.d ocument.myform. impiego;
var totalHours = 0;
var totalMins = 0;
for ( var n = 0 ; n < elems.length ; n++ )
{
if (elems[n].type == "text" && elems[n].value.match(re ))
{
var vals = elems[n].value.split(": ");
var hours = parseInt(vals[0]);
var mins = parseInt(vals[1]);
totalHours += hours;
totalMins += mins;
}
}
// validate outside the loop
if (totalHours > 7) {
alert("Error: total hours is more than 7");
return;
}
if ((totalHours == 7) && (totalMins > 36)) {
alert("Error: total time exceeds 7:36");
return;
}
// validation complete...
for ( var n = 0 ; n < elems.length ; n++ )
{
if (elems[n].type == "text" && elems[n].value.match(re ))
{
{
if (result.length) result += ";";
result += elems[n].name + "-" + elems[n].value;
}
}
destObj.value= result;
}
}[/code]Leave a comment:
-
[php]
function updateTime(txtO bj)
{
if (window.opener == null) return;
var re = /^([01]\d|2[0-3]):[0-5]\d$/;
if (txtObj.value.l ength >= 5 && !txtObj.value.m atch(re))
{
alert("Inserire l'orario nel formato 'hh:mm'.");
txtObj.focus();
}
var frmObj = txtObj.form;
var elems = frmObj.elements ;
var result = "";
var destObj = window.opener.d ocument.myform. impiego;
if (frmObj.IRE.val ue.match(re))
var totalHours = 0;
var totalMins = 0;
{
for ( var n = 0 ; n < elems.length ; n++ )
{
if (elems[n].type == "text" && elems[n].value.match(re ))
{
var vals = elems[n].value.split(": ");
var hours = parseInt(vals[0]);
var mins = parseInt(vals[1]);
totalHours += hours;
totalMins += mins;
}
{
if (result.length) result += ";";
result += elems[n].name + "-" + elems[n].value;
}
}
destObj.value= result;
}
else destObj.value= "--:--";
// validate outside the loop
if (totalHours > 7) // error
if ((totalHours == 7) && (totalMins > 36)) // error here too.
}
[/php]Leave a comment:
-
There are two problems: one is that you want to validate before you calculate the result. So make two loops. The second problem is that where I've added comments, e.g. // error, you need to replace that with an error message.Leave a comment:
-
Sorry Acoder, but not working....
[php]
function updateTime(txtO bj)
{
if (window.opener == null) return;
var re = /^([01]\d|2[0-3]):[0-5]\d$/;
if (txtObj.value.l ength >= 5 && !txtObj.value.m atch(re))
{
alert("Inserire l'orario nel formato 'hh:mm'.");
txtObj.focus();
}
var frmObj = txtObj.form;
var elems = frmObj.elements ;
var result = "";
var destObj = window.opener.d ocument.myform. impiego;
if (frmObj.IRE.val ue.match(re))
var totalHours = 0;
var totalMins = 0;
{
for ( var n = 0 ; n < elems.length ; n++ )
{
if (elems[n].type == "text" && elems[n].value.match(re ))
{
var vals = elems[n].value.split(": ");
var hours = parseInt(vals[0]);
var mins = parseInt(vals[1]);
totalHours += hours;
totalMins += mins;
}
{
if (result.length) result += ";";
result += elems[n].name + "-" + elems[n].value;
}
}
destObj.value= result;
}
else destObj.value= "--:--";
// validate outside the loop
if (totalHours > 7) // error
if ((totalHours == 7) && (totalMins > 36)) // error here too.
}
[/php]Leave a comment:
-
Just as you've used a loop in there, loop over the form elements in a similar manner:
[code=javascript]var totalHours = 0;
var totalMins = 0;
for ( var n = 0 ; n < elems.length ; n++ )
{
if (elems[n].type == "text" && elems[n].value.match(re ))
{
var vals = elems[n].value.split(": ");
var hours = parseInt(vals[0]);
var mins = parseInt(vals[1]);
totalHours += hours;
totalMins += mins;
}
}
// validate outside the loop
if (totalHours > 7) // error
if ((totalHours == 7) && (totalMins > 36)) // error here too.
[/code]Leave a comment:
Leave a comment: