473,378 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Perform control schedule

263 100+
Hi there.

Hi have this script:

Expand|Select|Wrap|Line Numbers
  1.  <script language="javascript" type="text/javascript">
  2. <!--
  3.  
  4. var fieldNames = new Array("IRE", "ISI", "IMI", "REL", "REV", "MAN", "SOP", "GUF", "FOR", "VAS");
  5.  
  6. function loaded()
  7. {
  8.  
  9.   var tm, q = location.href.indexOf("?tm=");
  10.   if (q < 0 || (tm = location.href.substr(q + 4)).length <= 0) return;
  11.  
  12.  
  13.   tm = tm.split(";");
  14.  
  15.   var frmObj = document.timeForm;
  16.  
  17.   var re = /^([a-z]+)-(([01]\d|2[0-3]):[0-5]\d)$/;
  18.  
  19.   for ( var n = 0 ; n < tm.length ; n++ )
  20.     {
  21.       var rt = tm[n].match(re);
  22.       if (rt && typeof(frmObj[rt[1]]) != "undefined")
  23.         {
  24.  
  25.           frmObj[rt[1]].value = rt[2];
  26.         }
  27.     }
  28. }
  29.  
  30. function unloading()
  31. {
  32.  
  33.   if (window.opener == null) return;
  34.  
  35.   window.opener.popupWin = null; 
  36. }
  37.  
  38. function updateTime(txtObj)
  39. {
  40.   if (window.opener == null) return;
  41.  
  42.   var re = /^([01]\d|2[0-3]):[0-5]\d$/;
  43.  
  44.   if (txtObj.value.length >= 5 && !txtObj.value.match(re))
  45.     {
  46.       alert("Inserire l'orario nel formato 'hh:mm'.");
  47.       txtObj.focus();
  48.     }
  49.  
  50.   var frmObj = txtObj.form;
  51.   var elems = frmObj.elements;
  52.  
  53.   var result = "";
  54.   var destObj = window.opener.document.myform.impiego;
  55.  
  56.     {
  57.       for ( var n = 0 ; n < elems.length ; n++ )
  58.         {
  59.  
  60.           if (elems[n].type == "text" && elems[n].value.match(re))
  61.             {
  62.               if (result.length) result += ";";
  63.  
  64.               result += elems[n].name + "-" + elems[n].value;
  65.             }
  66.         }
  67.  
  68.       destObj.value= result;
  69.     }
  70.   else destObj.value= "--:--"; 
  71. }
  72.  
  73. // -->
  74. </script> 

To perform control schedule.
That is schedule no superior to 7 hours and 36 minutes.

For example:

1) In the field of the form "IRE" inserted 08:00... this value is superior to 7:36
Its' wrong !!!!


2) In the field of the form "IRE" inserted 04:00 and in the field of the form "ISI" inserted 04:00.... this value is superior to 7:36
Its' wrong !!!!

Help me please, regards
viki1967
Feb 13 '08 #1
19 2271
acoder
16,027 Expert Mod 8TB
For each field, get the hours and minutes by splitting the input using split(). Use parseInt to convert into a number. Then add them up. If the hours are more than 7, then validation fails. If the hours equal 7, but the minutes exceed 36, again the validation fails. If you get stuck, post your attempt.
Feb 14 '08 #2
viki1967
263 100+
Sorry I not understand... for example ?
Feb 14 '08 #3
acoder
16,027 Expert Mod 8TB
For example, let's say you have 'field' which contains the input:
Expand|Select|Wrap|Line Numbers
  1. var vals = field.value.split(":");
  2. var hours = parseInt(vals[0]);
  3. var mins = parseInt(vals[1]);
  4. // if this is in a loop, you could now add them to the total hours/mins:
  5. totalHours += hours;
  6. totalMins += mins;
  7. // validate outside the loop
  8. if (totalHours > 7) // error
  9. if ((totalHours == 7) && (totalMins > 36)) // error here too.
  10.  
Feb 14 '08 #4
viki1967
263 100+
Sorry Acoder... but how to integrate your code with code existing ?
Many Thanks....
Feb 14 '08 #5
acoder
16,027 Expert Mod 8TB
Where are you making the validation? In updateTime()?
Feb 14 '08 #6
viki1967
263 100+
Yes Acoder in UpdateTime()
Feb 14 '08 #7
acoder
16,027 Expert Mod 8TB
Just as you've used a loop in there, loop over the form elements in a similar manner:
Expand|Select|Wrap|Line Numbers
  1. var totalHours = 0;
  2. var totalMins = 0;
  3. for ( var n = 0 ; n < elems.length ; n++ )
  4.   {
  5.      if (elems[n].type == "text" && elems[n].value.match(re))
  6.         {
  7.            var vals = elems[n].value.split(":");
  8.            var hours = parseInt(vals[0]);
  9.            var mins = parseInt(vals[1]);
  10.            totalHours += hours;
  11.            totalMins += mins;
  12.         }
  13.   }
  14. // validate outside the loop
  15. if (totalHours > 7) // error
  16. if ((totalHours == 7) && (totalMins > 36)) // error here too.
  17.  
Feb 14 '08 #8
viki1967
263 100+
Sorry Acoder, but not working....

[php]
function updateTime(txtObj)
{
if (window.opener == null) return;


var re = /^([01]\d|2[0-3]):[0-5]\d$/;


if (txtObj.value.length >= 5 && !txtObj.value.match(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.document.myform.impiego;


if (frmObj.IRE.value.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]
Feb 15 '08 #9
acoder
16,027 Expert Mod 8TB
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.
Feb 15 '08 #10
viki1967
263 100+
What solution for this script ?
Feb 15 '08 #11
acoder
16,027 Expert Mod 8TB
What changes have you made to the script?
Feb 15 '08 #12
viki1967
263 100+
[php]
function updateTime(txtObj)
{
if (window.opener == null) return;


var re = /^([01]\d|2[0-3]):[0-5]\d$/;


if (txtObj.value.length >= 5 && !txtObj.value.match(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.document.myform.impiego;


if (frmObj.IRE.value.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]
Feb 15 '08 #13
acoder
16,027 Expert Mod 8TB
I've made some quick changes without testing to give you an idea:
Expand|Select|Wrap|Line Numbers
  1. function updateTime(txtObj)
  2. {
  3.   if (window.opener == null) return;
  4.  
  5.   var re = /^([01]\d|2[0-3]):[0-5]\d$/;
  6.  
  7.   if (txtObj.value.length >= 5 && !txtObj.value.match(re))
  8.     {
  9.       alert("Inserire l'orario nel formato 'hh:mm'.");
  10.       txtObj.focus();
  11.     }
  12.  
  13.  
  14.   var frmObj = txtObj.form;
  15.   var elems = frmObj.elements;
  16.  
  17.  
  18.   var result = "";
  19.   var destObj = window.opener.document.myform.impiego;
  20.  
  21.   var totalHours = 0;
  22.   var totalMins = 0;
  23.  
  24.       for ( var n = 0 ; n < elems.length ; n++ )
  25.       {
  26.  
  27.  
  28.           if (elems[n].type == "text" && elems[n].value.match(re))
  29.           {
  30.            var vals = elems[n].value.split(":");
  31.            var hours = parseInt(vals[0]);
  32.            var mins = parseInt(vals[1]);
  33.            totalHours += hours;
  34.            totalMins += mins;
  35.           }
  36.       } 
  37.   // validate outside the loop
  38.   if (totalHours > 7) {
  39.     alert("Error: total hours is more than 7");
  40.     return;
  41.   }
  42.   if ((totalHours == 7) && (totalMins > 36)) {
  43.     alert("Error: total time exceeds 7:36");
  44.     return;
  45.   }
  46. // validation complete...
  47.       for ( var n = 0 ; n < elems.length ; n++ )
  48.       {
  49.  
  50.           if (elems[n].type == "text" && elems[n].value.match(re))
  51.           {
  52.             {
  53.               if (result.length) result += ";"; 
  54.  
  55.               result += elems[n].name + "-" + elems[n].value;
  56.             }
  57.         }
  58.  
  59.       destObj.value= result;
  60.     }
  61. }
Feb 15 '08 #14
viki1967
263 100+
Thanks Acoder.
But 09:00 value is validated by function...
Feb 15 '08 #15
acoder
16,027 Expert Mod 8TB
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.
Feb 15 '08 #16
viki1967
263 100+
How to change this ?

var hours = parseInt(vals[0]);
var mins = parseInt(vals[1]);
Feb 15 '08 #17
acoder
16,027 Expert Mod 8TB
var hours = parseInt(vals[0],10);
var mins = parseInt(vals[1],10);
Feb 15 '08 #18
viki1967
263 100+
Thanks Acoder !!!!!!
Feb 15 '08 #19
acoder
16,027 Expert Mod 8TB
You're welcome.
Feb 15 '08 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Beringer | last post by:
Hello, I am creating a custom schedule control similar to the way Outlook behaves. I am having some difficulty trying to graphically/visually resolve conflicting appointments on a schedule. ...
0
by: cyshao | last post by:
Hi, My Friends: I have a program and I want to let machine automaticly auto it by using Windows task schedule. Sure, I can manually Create/Modify task in Windows task schedule. But I also hope...
1
by: greg7224 | last post by:
I am currently working on a C# project that uses the Janus schedule controls, and am having trouble getting it to print correctly in Day view. The problem is that it will not print out the owners...
15
by: Tinus | last post by:
Hello all, I've created a custom control that draws a monthly schedule (using the Draw function in C#). Basically it draws 31 boxes and writes the day number in every box. This works...
1
by: Danny Ni | last post by:
Hi, I have one user control named Schedule.ascx, I want to create another control which is quite similar to schedule.ascx but differs in some methods and some UI elements, the way I am doing it...
0
by: Patrick | last post by:
I am using VB to implement a code behind class for an ASP.NET form. I am loading a DataGrid web server control with data from a table in a SQL database. the code is as follows: Private Sub...
2
by: John | last post by:
Hello everyone, I'm currently writing a program to keep track of schedule changes at a school. The goal is to have someone using the program to declare changes, then the program writes a html...
4
by: Yoram Biberman | last post by:
I have a few questions concerning concurrency control. I shall thank whoever can help me. Question #1 ========= Assume the following (concurrent) schedule, in which both transactions run in a...
1
by: Prakash | last post by:
Hi Friends, I am developing scheduler application using C#. For displaying all schedule information i am using ListView control. Based on the status of the schedule, i have displayed the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.