Note that there are some explanatory texts on larger screens.

plurals
  1. POImproving performance of jquery/javascript webpage logic
    primarykey
    data
    text
    <p>EDIT: I am also after advice if there is a better way to go about this??</p> <p>I have a webpage that displays a timesheet for the user to fill out. The timesheet is for a month so it has as many rows in the month and also 5 columns of data, Normal hours, extended hours, shift hours holidays hours and total.</p> <p>I have a dropdown list that allows the user to select the month and year textbox.</p> <p>When they select a month the code then disbles the bottom rows if they are not required due to not havving say 31 days as an example. It also then sets the background color of each row depending on if it is a weekend( in a different color) or not.</p> <p>Problem is when the month is selected it is taking 3-4 secs to run the code and is annoying for the user as they dont know what is happening.</p> <p>Is there any way of improving this that you can see? The code is shown below.</p> <pre><code> $('[id$=lstMonth]').change(function() { MonthChange(); }); }); function MonthChange() { var month = parseInt($('[id$=lstMonth]').val())-1; var year = $('[id$=txtYear]').val(); var daysInMonth = GetDaysInMonth(month, year); var day, dte, bgcolor; for(day=28; day&lt;=31; day+=1) { if(day &gt; daysInMonth) DisableRow(day); else EnableRow(day); } for(day=1; day&lt;=daysInMonth; day+=1) { dte = GetDate(day, month, year); bgcolor = GetInputFieldColor(dte, false); SetBackgroundColor(day, bgcolor); } } function SetBackgroundColor(day, bgcolor) { var selector = '[id$=txtNormal' + day + ']'; $(selector).css("background-color", bgcolor); $(selector).parent().css("background-color", bgcolor); selector = '[id$=txtExtended' + day + ']'; $(selector).css("background-color", bgcolor); $(selector).parent().css("background-color", bgcolor); selector = '[id$=txtShift' + day + ']'; $(selector).css("background-color", bgcolor); $(selector).parent().css("background-color", bgcolor); selector = '[id$=txtHoliday' + day + ']'; $(selector).css("background-color", bgcolor); $(selector).parent().css("background-color", bgcolor); selector = '[id$=txtTotal' + day + ']'; $(selector).css("background-color", bgcolor); $(selector).parent().css("background-color", bgcolor); } function DisableRow(day) { var selector = '[id$=txtNormal' + day + ']'; $(selector).css("background-color", "red"); } function EnableRow(day) { var selector = '[id$=txtNormal' + day + ']'; $(selector).css("background-color", "blue"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload