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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:47:54+00:00 2026-05-23T03:47:54+00:00

function Validator(formIsValid) { if(this.formIsValid) { alert(‘Form is valid!’); } else { alert(‘Form is invalid…’);

  • 0
function Validator(formIsValid) {
    if(this.formIsValid) {
        alert('Form is valid!');
    }
    else {
        alert('Form is invalid...');
    } 
}
Validator.prototype = { // Notice the .prototype here, it's important!

  formIsValid: true, 

  enforceTextFieldMinLength: function(field, minLength) {
      if (!field.value || field.value.length < minLength) {
            this.formIsValid = false;
      }   
  },

  enforceLabelHasText: function(label) {
        if (!label.text) {
            this.formIsValid = false;
        }
  }
}
//var val = new Validator();

The above is my Val.js. This is how i am using in my otherFile.js

AddPatient.Firstname = FirstNameValue || Validator.enforceLabelHasText(FirstName);  

I get an error saying cannot find function enforceLabelHasText in Object function Validator(formIsValid)

  • 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-23T03:47:55+00:00Added an answer on May 23, 2026 at 3:47 am

    You can’t put expressions in an object definition. If you want code to be executed after an object instance is created, you should use:

    function Validator() {
        if(this.formIsValid) {
            alert('Form is valid!');
        }
        else {
            alert('Form is invalid...');
        } 
    }
    Validator.prototype = { // Notice the .prototype here, it's important!
    
      formIsValid: true, 
    
      enforceTextFieldMinLength: function(field, minLength) {
          if (!field.value || field.value.length < minLength) {
                this.formIsValid = false;
          }   
      },
    
      enforceLabelHasText: function(label) {
            if (!label.text) {
                this.formIsValid = false;
            }
      }
    }
    var a = new Validator();
    

    This is a dummy solution; you will want to add arguments to the Validator() function, to initialize formIsValid and the other values. I suggest you should read the MDC’s description on prototypes.

    EDIT: If you went with the prototype solution, you need to call val.enforceLabelHasText(FirstName), after making val a global variable (either by omitting the var or by using var window.val = new Validator()).

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

Sidebar

Related Questions

I have a Javascript form validator function something like switch (element.getAttribute('validationtype')) { case 'text':
I have been struggling with this jQuery Validation Plugin. Here is the code: <script
I have this compare validator: <asp:CompareValidator ID=cpvBirthDate Type=Date ControlToValidate=txtBirthDate Operator=DataTypeCheck runat=server ErrorMessage=Please enter a
This is beyond both making sense and my control. That being said here is
I'm using the jQuery validation plugin found here: http://plugins.jquery.com/project/validate In my form I have
I have a custom validation function in JavaScript in a user control on a
I want to invoke a validation function inside the entities objects right before they
I am writing a client-side validation function for CustomValidator and I need to check
Calling Validate() on an XmlDocument requires passing in a ValidationEventHandler delegate. That event function
function Submit_click() { if (!bValidateFields()) return; } function bValidateFields() { /// <summary>Validation rules</summary> ///

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.