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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:05:32+00:00 2026-06-04T11:05:32+00:00

I want to detect if this text field is empty or not and then

  • 0

I want to detect if this text field is empty or not and then run some code based on that.

Question is: how can I run the code only once …and then run it once again each and every time that the state of the text field changes during one focus

  • Different states being empty or not empty.

To further elaborate:

( The most important part in these jsfiddle’s are shown in the console. )

  • Here is a jsfiddle of a code that executes the code every
    time you keyup (Not what I want. Just the initial code. ).

    $('input').on("keyup", function() {
    
        var val = $(this).attr('value'),
            previous = $(this).prev();
    
        if ( val === '' ) {
            console.log('Empty');
        }
        else if ( val !== '' ) {
            console.log('Text');
        }
    
    });
    
  • and Here is a jsfiddle of a code that executes the code once
    per focus (This is somewhat near to what I want).

    What it is still missing, and what I can’t seem to get done, is to basically run the code once again each and every time that the state
    changes during that one focus.
    How could I do that?

    $('input').on("focus", function() {
    
        $('input').one("keyup", function() {
    
            var val = $(this).attr('value'),
                previous = $(this).prev();
    
            if ( val === '' ) {
                console.log('Empty');
            }
            else if ( val !== '' ) {
                console.log('Text');
            }
    
        });
    
    });
    
  • 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-04T11:05:34+00:00Added an answer on June 4, 2026 at 11:05 am

    You need to use a plugin called jQuery Text Change from ZURB. Does everything you want and more, also has a trigger action called ‘hastext’ and ‘notext’, take a look at:

    http://www.zurb.com/playground/jquery-text-change-custom-event

    there are also demos there.

    I made this for you (using that plugin).

    LIVE DEMO:

    http://jsfiddle.net/oscarj24/UtwNz/

    Hope this helps 🙂

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

Sidebar

Related Questions

I have a text box in my form that I want to detect if
I am wanting to display a text field stating that my listview is empty
I want to detect when the document has just started to load, so that
Edited // I want to detect flash support ( not user string agent )
I have three UILabels. I want to detect which label is Tapped, and then
I want to detect Empty paragraphs in Word Document using Microsoft.Office.Interop.Word. Suppose, if my
Here is a language translation code that google provides to detect the language in
hi all i have a string text that may contains urls (this text is
I have input field <input type=text name=vehicle_make[] id=make1/> and i have help dropdown that
I have a string in c# How can i detect if this string contains

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.