Perform control schedule

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • acoder
    replied
    You're welcome.

    Leave a comment:


  • viki1967
    replied
    Thanks Acoder !!!!!!

    Leave a comment:


  • acoder
    replied
    var hours = parseInt(vals[0],10);
    var mins = parseInt(vals[1],10);

    Leave a comment:


  • viki1967
    replied
    How to change this ?

    var hours = parseInt(vals[0]);
    var mins = parseInt(vals[1]);

    Leave a comment:


  • acoder
    replied
    Originally posted by viki1967
    Thanks Acoder.
    But 09:00 value is validated by function...
    Use the radix to parse the number as a decimal, i.e. use parseInt(val,10 ) as described here.

    Leave a comment:


  • viki1967
    replied
    Thanks Acoder.
    But 09:00 value is validated by function...

    Leave a comment:


  • acoder
    replied
    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:


  • viki1967
    replied
    [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:


  • acoder
    replied
    What changes have you made to the script?

    Leave a comment:


  • viki1967
    replied
    What solution for this script ?

    Leave a comment:


  • acoder
    replied
    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:


  • viki1967
    replied
    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:


  • acoder
    replied
    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:


  • viki1967
    replied
    Yes Acoder in UpdateTime()

    Leave a comment:


  • acoder
    replied
    Where are you making the validation? In updateTime()?

    Leave a comment:

Working...