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

  • Home
  • SEARCH
  • 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 6596173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:02:25+00:00 2026-05-25T18:02:25+00:00

I have a comment form with a textarea, input text and input radio. first,

  • 0

I have a comment form with a textarea, input text and input radio. first, you’ll see the textarea. if you click in it, the whole form expand. When you click outside the form and the fields have no values, the form should reduce to the textarea again. This works as well.

The problem is, when you switch from field to field inside the form, the form reduces and expand, and again and again. The if ($this.not(":focus")) will not help out.
Any ideas?

HTML

<div id="commentBox">
    <form action="...">
        <label for="comment">Write a comment...</label>
        <textarea id="comment"></textarea>

        <div class="expandBox" style="display: none">
            <label for="title">Title</label>
            <input type="text" id="title" />
            <br />
            <label for="email">E-Mail *</label>
            <input type="text" id="email" />
            <br />
            <label for="name">Newsletter</label>
            <input type="radio" id="yes" name="newsletter" /><label for="yes">ja</label>
            <input type="radio" id="no" name="newsletter" /><label for="no">nein</label>
            <br />
            <label for="name">Name *</label>
            <input type="text" id="name" />
            <br />
            <input type="submit" value="senden" />
        </div>

    </form>
</div>

jQuery snippet (in domready off course)

$("#commentBox").find("input,textarea").each(function() {
    var $this = $(this);
    var $expandBox = $this.parents("#commentBox").find(".expandBox");

    $this.focus(function() { 
            $expandBox.slideDown(250);
    });

    $this.blur(function() {
            if ($this.val() === "" && $this.not(":focus")) {
                    $expandBox.slideUp(250);
            }
    });
});
  • 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-25T18:02:26+00:00Added an answer on May 25, 2026 at 6:02 pm

    The problem is that when you switch between inputs/textareas, focus() is triggered on the new focused element, and blur() on the last one.

    $expandBox is thus asked to slideUp() AND slideDown().

    To fix this problem, you have to tell these animations to stop previous animations when they’re called. That way, slideUp() will be called, and immediately stopped by slideDown().

    Use stop() for that.

    $("#commentBox").find("input,textarea").each(function() {
        var $this = $(this);
        var $expandBox = $this.parents("#commentBox").find(".expandBox");
    
        $this.focus(function() { 
                $expandBox.stop().slideDown(250);
        });
    
        $this.blur(function() {
                if ($this.val() === "" && $this.not(":focus")) {
                        $expandBox.stop().slideUp(250);
                }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this form: <form name=commentform id=commentform action=comment.php method=post enctype=multipart/form-data> Your Name: <textarea maxlength=60
I have a simple contact form on a website that has 2 text fields,
hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
I have a form on a website I'm working ( you can see it
I have following html form: <form method=post action=> <input type=hidden name=userid id=user value=<?php echo
I have a single text area input that I would like to get as
I have a live preview form: http://davidwalsh.name/jquery-comment-preview Which uses jquery to display the preview
For example Imagine I have the following form <%= form_for(@comment) do |f| %> <%=
I have code similar to the below <form action=/u method=post> <div class=reply> <input type=hidden
I have this textarea form: self.response.out.write( <form name=title action=/edittitlepitchhandler method=post> ... pitch: <br />

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.