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

  • Home
  • SEARCH
  • 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 8452831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:36:16+00:00 2026-06-10T11:36:16+00:00

My knowledge of jQuery and more specifically javascript has always been very limited and

  • 0

My knowledge of jQuery and more specifically javascript has always been very limited and I am working hard to get better.

With that in mind I am trying to create some sort of “extensible validation framework” in that I can create an object with a validation function and its error message, push it into an array and then call all those methods and report the messages from the ones that fail.

So first I did something very simple just to see that the basic validation worked which was this:

var selectedTourDate = $("#tourDate").val();
var list = $("#bookedTourDate *");

var isDateBooked = list.filter(function () {
    return (this.innerHTML == selectedTourDate) ;
}).length !== 0;

if (isDateBooked) {
    alert("Date invalid");
    return;
}

This works fine.

Then I created my “framework” which is this:

function Validator(fn, errorMessage) {
    this.validationFunction = fn;
    this.errorMessage = errorMessage;
};

var validationRunner = {
    validators: [],
    errorMessages: [],
    validationResult: true,

    addValidation: function (validator) {
        validationRunner.validators.push(validator);
    },

    validate: function () {
        for (var validator = 0; validator < validationRunner.validators.length; validator++) {
            if (validationRunner.validators[validator] instanceof Validator) {
                var result = validationRunner.validators[validator].validationFunction();
                validationResult = validationRunner.validationResult && result;

                if (!result)
                    validationRunner.errorMessages.push(validationRunner.validators[validator].errorMessage);
            }
        }
    },

    getErrorMessage: function () {
        var message = "<ul>";

        for (var errorMessage = 0; errorMessage > validationRunner.errorMessages.length; errorMessage++) {
            message += "<li>" + errorMessage + "</li>";
        }

        message += "</ul>";
        return message;
    }
}

And then modified the first block of code as follows:

var selectedTourDate = $("#tourDate").val();
var list = $("#bookedTourDate *");

var tmp = new Validator(function () {
    return list.filter(function () {
         return (this.innerHTML == selectedTourDate);
    }).length !== 0;
}, "Date already booked");

validationRunner.addValidation(tmp);
validationRunner.validate();
var msg = validationRunner.getErrorMessage();

This does not work at all.

It seems that the problem is that in this statement:

return (this.innerHTML == selectedTourDate);

The “this” is the Validator object instead of the html element from the list which confuses me since as its inside the function of the “filter” method it should be.

Is there a way to correct this so I can accomplish what I am trying to do here?

  • 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-06-10T11:36:18+00:00Added an answer on June 10, 2026 at 11:36 am

    this does have the correct value but there are some mistakes in the getErrorMessage function.

    To check the value of this don’t rely on a debugger’s “watch variable” function but do a console.log which will give you the value at a specific point of the code execution.

    My changes:

        for (var errorMessage = 0; errorMessage < validationRunner.errorMessages.length; errorMessage++) {
            message += "<li>" + validationRunner.errorMessages[errorMessage] + "</li>";
        }
    

    The errorMessage variable is only a index and not the actual error message. Also you used a “bigger than” instead of a “smaller than” sign.

    Here’s a fiddle

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

Sidebar

Related Questions

I have been working on a project that dynamically creates a javascript file using
With my very limited knowledge of both jQuery and JS i made a small
I have a fair knowledge about Javascript, I started with jQuery 1.4 a week
It's pretty common knowledge that JQuery is in both the Microsoft and Google CDN,
I understand that Dart has just been released, and while it's not entirely stable
So I don't have that much experience with js or jquery and I'm working
My knowledge of jquery isn't very vast but what I'm trying to do is
I am wondering if anyone has any experience using a JQuery plugin that converts
I am trying to learn more about Javascript, I have been coding with PHP
Hi I've been busy trying to take my knowledge of JQuery to the next

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.