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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:40:17+00:00 2026-05-16T10:40:17+00:00

I am only 2 days into jquery so I’m probably making a simple error

  • 0

I am only 2 days into jquery so I’m probably making a simple error here. Basically I have a input field that when clicked gets a blue border around it (doing this by having a css class be added to the input field on keyup and the css adds the border color). On keyup the submit button also shows. The only other thing I want is to show a remaining character count. Everything else works except the last part. Here’s all my code:

<style type="text/css">.onFocus { border:3px solid #BBDAFD; }</style>

<script type="text/javascript">
    $(document).ready(function(){

        $('.submitButton').hide();
        $('.remaining').hide();

        var typed = $('input1').val();

        $('.input1').keyup(function(){
            $('.input1').addClass('onFocus');
            $('.submitButton').show();
            $('.remaining').show().html(150 - typed);
        });

    });
</script>

<form action="submitComment.php" name="" method="post">
    <label>Leave a comment</label>
    <input type="text" class="input1" maxlength="150" />
    <br />
    <span class="remaining"></span>
    <br />
    <input type="button" name="commentSubmit" value="Submit Comment" class="submitButton" />
</form>

Instead of executing the operation 150 (which is the max character limit I want to allow) from the present value of the input field which should be stored in the variable “typed”, instead jquery just splits out:

NaN

What is the problem/solution here?

EDIT

Opps, just noticed that this:

var typed = $('input1').val();

should be:

var typed = $('.input1').val();

Now NAN doesn’t show but 150 shows. So the operation is still not being performed.

  • 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-16T10:40:17+00:00Added an answer on May 16, 2026 at 10:40 am

    This:

        var typed = $('input1').val();
    
        $('.input1').keyup(function(){
            $('.input1').addClass('onFocus');
            $('.submitButton').show();
            $('.remaining').show().html(150 - typed);
        });
    

    Needs to look like this:

        $('.input1').keyup(function(){
            $(this).addClass('onFocus');
            $('.submitButton').show();
            $('.remaining').show().html(150 - this.value.length);
        });
    

    It’s important to check the current value length inside the keyup handler, otherwise you’re always checking against what the value length was on document.ready.

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

Sidebar

Related Questions

I have been building my own carasol over the past few days. My Jquery
I have ran into a really annoying issue which gives me this error: The
I have been working three days straight to try and integrate ads into my
I have a view that displays a table: rows represent days - one row
I am seeing a lot of sites these days, mainly tutorial sites that have
Bit of a jquery Newbie here, so go easy. Basically I'm trying to plug
Some days ago I run into a severe problem that gives me a headache:
I've got a school project, kind of huge, and only a few days left,
I only want log4net to keep let's say 10 days-worth of log files as
We need to make sure only results within the last 30 days are returned

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.