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 6843639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:16:10+00:00 2026-05-27T00:16:10+00:00

What can I do to this piece of code to ensure that it can

  • 0

What can I do to this piece of code to ensure that it can allow absences to be added in the past as well as the future? Whenever I attempt to add anything in the past, it is appears to want to still give me the error that I cannot add an absence in the past. I’m not even sure how to code to ensure it can, or which bit to delete. I’m aware there is a bit of code that is not allowing me to, but I’m not sure which bit and what to delete. I am not extremely skilled at JavaScript but it is in my project and I am unsure what to do with it.

dateValid: function () {
    var s = $(this).val();

    if ($(this).required()) {
        var date = new Date(s);

        if (!isNaN(date)) {
            if (date >= Date.parse(new Date().toDateString())) {
                $(this).removeClass("error");
                return true;
            }
            else {
                validation.showError("Past", $(this).attr("name"));
                $(this).addClass("error");
                return false;
            }
        }
        else {
            validation.showError("Invalid", $(this).attr("name"));
            $(this).addClass("error");
            return false;
        }
    }
    else return false;
},

dateRangeValid: function (toDate) {
    var s = $(this).val();

    if ($(this).required()) {
        if (toDate.required()) {
            var dateFrom = new Date(s);
            var dateTo = new Date(toDate.val());

            if (!isNaN(dateFrom) && !isNaN(dateTo)) {
                if (dateTo >= dateFrom) {
                    if (dateFrom >= Date.parse(new Date().toDateString())) {
                        $(this).removeClass("error");
                        toDate.removeClass("error");
                        return true;
                    }
                    else {
                        validation.showError("Past", "date");
                        $(this).addClass("error");
                        toDate.addClass("error");
                        return false;
                    }
                }
                else {
                    validation.showError("Invalid", "date");
                    $(this).addClass("error");
                    toDate.addClass("error");
                    return false;
                }
            }
            else {
                validation.showError("Invalid", "date");
                $(this).addClass("error");
                toDate.addClass("error");
                return false;
            }
        }
        else {
            validation.showError("Required", "dateTo");
            $(this).addClass("error");
            toDate.addClass("error");
            return false;
        }
    }
    else {
        validation.showError("Required", "dateFrom");
        $(this).addClass("error");
        toDate.addClass("error");
        return false;
    }
},
  • 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-27T00:16:10+00:00Added an answer on May 27, 2026 at 12:16 am

    Here’s your error:

                if (dateTo >= dateFrom) {
    
                    // This if statement checks if dateFrom is today or later!!
                    if (dateFrom >= Date.parse(new Date().toDateString())) { 
    
                        $(this).removeClass("error");
                        toDate.removeClass("error");
                        return true;
                    }
                    else {
                        validation.showError("Past", "date");
                        $(this).addClass("error");
                        toDate.addClass("error");
                        return false;
                    }
                }
    

    Replace with

                if (dateTo >= dateFrom) {
                    $(this).removeClass("error");
                        toDate.removeClass("error");
                        return true;
                }
    

    and there should no longer be a problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way that I can change this piece of code to work
I have this piece of code for my images, so the opacity can lower
I am stuck on this one piece of code because I can't get the
Can anyone help me figure out whats wrong with this piece of xaml code?
I need to change a piece of code which includes this: string.indexOf(bc) How can
I have this piece of code that finds words that begin with @ or
I have made this piece of code that makes a roll hover effect on
Can someone please tell me how I can use this piece of code?. I'm
I'm having a weird situation that I'm trying to understand. This piece of code
Can someone please break down this piece code for me? I'm not sure exactly

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.