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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:57:45+00:00 2026-06-05T05:57:45+00:00

I have simple comment form . I put char-counter . When i create new

  • 0

I have simple comment form . I put char-counter . When i create new comment all work fine. When i try to edit comment ,char-counter doesnt work.I tried whit Live(), but result is the same. Other Js in edit page is work fine, just this keyup function is die. I tried to put alert to see whether keyup works, but no responce.
Here is my code:

  • html

        <?php echo form_tag_for($form, '@comments',array('class' => 'nice'));?>
    
            <?php echo $form->renderHiddenFields() ?>
            <?php echo $form->renderGlobalErrors() ?>
            <?php echo $form['_csrf_token']; ?>
            <input type="hidden" name="comments[users_id]" id="comments_users_id" value="1" />
            <input type="hidden" name="comments[tests_id]" id="comments_users_id" value="<?php echo $testId?>" />
    
    
            <?php echo $form['comment']->renderError() ?>
    
              <div class="count">remaining symbols : 250</div>
              <div class="barbox"><div class="bar"></div></div>
    
            <?php echo $form['comment']->render(array('class' => 'comments_comment')) ?>
    
            <?php  echo $form['captcha']->renderLabel(null,array('class' => 'label-login-down ')) ?>
            <?php echo $form['captcha']->renderError() ?>
            <?php echo $form['captcha']->render(array('class' => 'normal  input-text ' , 'placeholder'=>"Въведете символите")) ?>
    
            <input type="submit" name="addComment" value="Изпрати" />          
        </form> 
    
  • jquery

    $(".comments_comment").keyup(function()
    {       
      var box=$(this).val();
      var main = box.length *100;
      var value= (main / 250);
      var count= 250 - box.length;
    
      if(box.length <= 250)
      { 
        if(box.length <=210)
        {
         $('.count').html('remaining symbols : '+count);            
        }
        else
        {          
       $('.count').html('<div class="commentAlertSymbols">remaining symbols :    '+count+'</div>'); 
        }
      $('.bar').animate(
      {
      "width": value+'%',
      }, 1);
    
    }
    else
    {
      $('.count').html('<div class="commentRedSymbols">remaining symbols : '+count+'</div>');
    }
    return false;
    });
    
  • 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-05T05:57:46+00:00Added an answer on June 5, 2026 at 5:57 am

    It would have been nice to see the actual form HTML output instead of all those PHP helper functions, but I’ll give it a shot:

    $('.comments_comment').keyup(function() {
        // Get the number of characters, percent used, and number left
        var $count = $('.count');
        var chars = $(this).val().length;
        var percent = (chars / 250) * 100;
        var left = 250 - chars;
    
        // Update the counter
        $count.html('Remaining Symbols: ' + left);
    
        // Add classes based on how many are left
        if (chars > 210 && chars <= 250) {
            $count.addClass('commentAlertSymbols');
        } else if (chars > 250) {
            $count.addClass('commentRedSymbols');
        }
    
        // Animate the bar
        $('.bar').css({
            width: chars <= 250 ? percent + '%' : '100%'
        });
    });
    

    I made the code more DRY. Also, I changed the $('.bar').animate line to $('.bar').css, because I didn’t see the point of animating something over one second.

    You can see a working JSFiddle at http://jsfiddle.net/KjTrj/.

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

Sidebar

Related Questions

This is probably a simple question, I have a form that you put in
I have a simple Django form: class CommentForm(forms.Form): comment = forms.CharField(max_length=2000, required=True) post_id =
I have a simple Comment model and controller. When I create a comment in
i have simple form that uploads image to server and returns php string containing
I have simple component - CommandButton <tr:commandButton text=test styleClass=form-button actionBean=#{testPage} action=synchAction partialSubmit=true id=btnId />
I have simple form with a textarea and a button, and I submit the
I'm new to ASP.NET MVC and I'm trying to create a very simple blog
I have a simple phone list with columns in the form of Name, Address,
I'm working on a simple JavaScript validation function for a html form, but have
I have a very simple contact form on my site, Im looking for users

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.