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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:40:43+00:00 2026-06-13T00:40:43+00:00

I’m showing errors in the above fields, but I want to add styling near

  • 0

I’m showing errors in the above fields, but I want to add styling near it, e.g., add some image as background into the containing div.

I’m adding it like this:

  $('input').change(function() {

  if ($(this).hasClass('valid')) {

  $(".field2").has(this).removeClass('bg2').addClass('bg1');
   }
  if ($(this).hasClass('error')) {

  $(".field2").has(this).removeClass('bg1').addClass('bg2');

   }
  })

and css:

.bg1 
  { 
  background-image: url('valid.png');
  background-repeat: no-repeat;
  background-position:320px 25px;
  }

 .bg2 
  {
   background-image: url('not_valid.png'); 
   background-repeat: no-repeat;
   background-position:320px 25px;
  }

But now it working like this:

  1. Firstly jQuery validation form appears
  2. Then, my bg adding ONLY on next input changing and clicking out of the form

I want to make background appears together with fields.

Can do it using simple jQuery events?
OR

Should I add error labels for this? If so – please, supply an example of validation with form and labels WITHOUT error text if it is possible.

  • 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-13T00:40:44+00:00Added an answer on June 13, 2026 at 12:40 am

    As Saeed Py said, you should use keyup/keydown event instead of change. The problem with chance event is that it is triggered only when the input element loose the focus.

    You could change it for either keydown/keyup/keypress to validate input on every key press. You could also add click event, in the case of a user pasting data with the mouse only.

    I have made a quite simple jsfiddle demoing the difference between those 3 events. (It’s kinda incomplete as I didn’t use any field validation…).

    As for your javascript, it should probably be more like this :

    if ($(this).hasClass('valid')) {
      $(".field2").has(this).removeClass('bg2').addClass('bg1');
    }
    

    Should probably be written as

    if ($(this).hasClass('valid')) {
      $(".field2").has($(this)).removeClass('bg2').addClass('bg1');
    }
    

    this -> $(this)

    Of course, this depends on more markup then what you showed us. I’m assuming a div with a common class surrounding each input, as displayed in my jsfiddle.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I want to construct a data frame in an Rcpp function, but when I
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm interested in microtypography issues on the web. I want a tool to fix:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.