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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:33:50+00:00 2026-05-26T18:33:50+00:00

I have this javascript which is working great – var employeename = $(#employeename); var

  • 0

I have this javascript which is working great –

var employeename = $("#employeename");
var employeenameInfo = $("#employeenameInfo");
employeename.blur(validateEmployeename);

function validateEmployeename(){
    //if it's NOT valid
    if(employeename.val().length < 4){
        employeename.addClass("error");
        employeenameInfo.text("We want names with more than 3 letters!");
        employeenameInfo.addClass("error");
        return false;
    }
    //if it's valid
    else{
        employeename.removeClass("error");
        employeenameInfo.text("Full Name.");
        employeenameInfo.removeClass("error");
        return true;
    }
}

However instead of having a big list of this functions for all my different fields I want to pass a field in e.g.

function validateGeneric(field){

However whatever I try just gives me errors and I’m really stuck. Any help appreciated. This also brings up another problem with the info field, any way I can store the orginal text and just restore that instead of a new string?

  • 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-26T18:33:51+00:00Added an answer on May 26, 2026 at 6:33 pm

    You can get the field that triggered the event using $(this). also you should put the info field as a sibling with an info class

    $('input.to_be_validated').blur(validateInput);
    
    function validateInput(e){
        var input = $(this)
        var info = input.parent.find('.info')
        //if it's NOT valid
        if(input.val().length < 4){
            input.addClass("error");
            info.text("We want names with more than 3 letters!");
            info.addClass("error");
            return false;
        }
        //if it's valid
        else{
            input.removeClass("error");
            info.text("Full Name.");
            info.removeClass("error");
            return true;
        }
    }
    

    Edit: forgot about the info field

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

Sidebar

Related Questions

Hi Javascript gurus, I have this Javascript code which is working fine on Firefox
I have this function in javascript file which works perfectly fine in Firefox /
i have this javascript code to which i want to add the jquery fade-in
I have a sample.xhtml file which has few lines of javascript. This javascript will
I have a javascript page which checks an email and username, this works fine
I have a file called bbUI.js which contains this bit of JavaScript. Outside of
I have a chrome extension which have a server-side javascript and I need this
I have this Javascript function that sends username and password to php file through
I have this Javascript: <script language=javascript type=text/javascript> $().ready(function() { $('#ex2').jqm({ajax: 'view.php?id=<?=$objResult[id];?>', trigger: 'a.ex2trigger'}); });
I have this code which depends on this javascript from dynamic drive: http://dynamicdrive.com/dynamicindex16/formdependency.htm Its

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.