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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:59:25+00:00 2026-05-16T06:59:25+00:00

Trying to do some jQuery validation (without the plugin – please no answers like

  • 0

Trying to do some jQuery validation (without the plugin – please no answers like “Just use the validate-js plugin”).

I’m wiring up a client-side event handler keypress for each “required field” on doc ready:

$(document).ready(function() {
  $('#myform input.required').each(function() {
    $(this).keypress(onRequiredFieldKeyPress);
  });
});

Which correctly fires this event on each keypress:

function onRequiredFieldKeyPress() {
   if ($(this).val().trim() == '') {
      $(this).next('em').html('*').show(); // show req field indicator
   } else {
      $(this).next('em').html('*').hide(); // hide req field indicator
   }
}

But $(this).val() is always null/empty. Looks like it’s passing in an “HTMLInputElement” which is what i’d expect, but it’s almost like i have to project this into some other jQuery type?

Essentially i’m trying to do this: on the keypress event of any field which i have wired-up (which are all input elements), call that function. In that function, if that field has a value of ” (empty), then show a hidden field which displays a required field indicator.

I don’t really care which actual element fired the keypress, as the behaviour of my logic will be the same. I just need to get the actual value.

Am i missing something?

  • 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-16T06:59:26+00:00Added an answer on May 16, 2026 at 6:59 am

    Because you are using key-press event. Key press has 3 phase:
    1. Key down: when key is press
    2. Key hold: key is hold down
    3. Key up: key is release
    In your case, problem can be solved by using keyup event

    $(document).ready(function() {
      $('#myform input.required').each(function() {
        $(this).keyup(onRequiredFieldKeyPress);
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If your Main class is in a package called FileManagement,… May 16, 2026 at 5:55 pm
  • Editorial Team
    Editorial Team added an answer If you're willing to forget about backwards compatibility, SSE is… May 16, 2026 at 5:55 pm
  • Editorial Team
    Editorial Team added an answer Check CLinq (here and here) or Linq++ (here). Also try… May 16, 2026 at 5:55 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am trying to use jquery validation to validate some input values on the
I'm trying to add the jQuery Validation plugin to some websites and I'm running
Hi there Im trying to do a few things with jQuery validation plugin and
I am using the popular jQuery Validation Plugin . It's very flexible with regards
I have a jQuery Dialog form and on submit I'm trying to validate the
I'm trying to do some validation on 2 numerical fields and not done much
I'm trying to style some cells of a jquery-ui date picker based on application
I need some help with jQuery syntax. I'm trying to modify the opacity effect
I am trying to clean up some of the JavaScript throughout my views and
I am trying out some globalization in an asp.net mvc2 application but can't get

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.