p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Beginning VB.NET Databases (http://p2p.wrox.com/book-beginning-vb-net-databases-147/)
-   -   Ch14 - timesheets with one row (http://p2p.wrox.com/book-beginning-vb-net-databases/32816-ch14-timesheets-one-row.html)

geoffers August 24th, 2005 09:48 AM

Ch14 - timesheets with one row
 
If the timesheet only has a single row, the function Recalculate doesn't work, as txtMondayHours is not treated as an array, so doesn't have a .length property. Tabbing from the last entry also fails, as txtMondayHours[0] does not exist (not an array)
I've modified the code as follows to get round this -

function Recalculate(dayofweek)
{
   //Get the number of rows
   var intCount = 0
   if (document.Form1.txtMondayHours.length > 0)
   {
      intCount=document.Form1.txtMondayHours.length;
   }

   //Find the day of the week that you are working with
   switch (dayofweek)
   {
      case "Monday":
         //Set the current total to 0 as it will be recalculated
         document.Form1.txtMondayTotal.value = 0;
         //Process each row of data adding it to the total
         if (intCount == 0)
         {
         document.Form1.txtMondayTotal.value =
         parseInt(document.Form1.txtMondayHours.value);
         break;
         }

         for (i=0;i<intCount;i++)
         {
            document.Form1.txtMondayTotal.value =
               parseInt(document.Form1.txtMondayTotal.value) +
               parseInt(document.Form1.txtMondayHours[i].value);
         }
         break;
       case "Tuesday":
         etc...
         etc...
   }
}

function tabSelect()
{
   if (document.Form1.txtMondayHours.length > 0)
   {
      document.Form1.txtMondayHours[0].select();
        document.Form1.txtMondayHours[0].focus();
   }
   else
   {
         document.Form1.txtMondayHours.select();
        document.Form1.txtMondayHours.focus();
   }
}

in TimeSheet.aspx.vb>>>>>>>>

Public Sub DisplayTimeSheet()
...
...
       'Write the total row
...
...
        Response.Write("<td><INPUT type=""text"" name=""txtMondayTotal""" & _
             "class=""TransparentTextBox"" readonly " & _
             "onfocus=""javascript:tabSelect();"" value=""" & _
             objTimeSheetDS.Tables("TimeSheet").Rows(intIndex). Item( _
             "MondayHours") & """></td>" & ControlChars.CrLf)
...
...





All times are GMT -4. The time now is 09:21 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.