Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 290613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:00:50+00:00 2026-05-12T06:00:50+00:00

EDIT: I am also after advice if there is a better way to go

  • 0

EDIT: I am also after advice if there is a better way to go about this??

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.

I have a dropdown list that allows the user to select the month
and year textbox.

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.

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.

Is there any way of improving this that you can see? The code
is shown below.

    $('[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<=31; day+=1) {
        if(day > daysInMonth)
            DisableRow(day);
        else
            EnableRow(day);
    }

    for(day=1; day<=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");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:00:50+00:00Added an answer on May 12, 2026 at 6:00 am

    You are using all over your code, attribute selectors without specifying the element type.

    This is not well performing, since all your DOM elements are inspected, for example:

    You are also using endsWith [id$=xxx] this is really needed for your case??

    I would consider rewriting your SetBackgroundColor function as this also for readability:

    function SetBackgroundColor(day, bgcolor) {
      var types = ['Normal', 'Extended', 'Shift', 'Holiday'];
    
      $.each(types, function(index, type){
        var selector = 'input[id$=txt' + type + day + ']'; // change input to your
                                                           // element type
                    //'#txt' + type + day; or if you don't need the endsWith selector
        $(selector).css("background-color", bgcolor)
                   .parent()
                   .css("background-color", bgcolor);
        // 1 selector call, and using chaining
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: There's now a doc page on this so this question is irrelevant, also
I have this so far: http://jsfiddle.net/26eVE/4/ I want that when the user clicks on
Is it possible to pass the coloumn name also like a variable.Please edit this
EDIT: See my answer below--> I am wanting to have a view that when
I have been reading a lot about test-driven development and decided that I want
I have a simple django app that is using only the admin. This is
EDIT 4 July: Still struggling with this issue. I'm sure all that's required is
There's this program, pdftotext, that can convert a pdf file to a text file.
I want to copy my NSDictionary's data into plist and also edit some data
LATER EDIT: Please mention not only game programming books, but also more scientific/simulation oriented

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.