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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:48:00+00:00 2026-05-18T08:48:00+00:00

I have modified my comments/form.html and comments/posted.html to work in a similar way to

  • 0

I have modified my comments/form.html and comments/posted.html to work in a similar way to facebook, ie you post a comment, the data posted is then reloaded and appended to a certain div with a given ID.

The problem I have is that it seems to post all the data for the amount of forms.

So the scenario is, I have 5 forms, one with data in it, if I then hit comment, it submits the data, 1 successful but 4 return empty.

<div id="commentload"></div>
<div class="comments">
    <form action="{% comment_form_target %}" method="post" class="comment-form">
    {% if next %}<input type="hidden" name="next" value="{{ next }}" />{% endif %}
    {% for field in form %}
        {% if field.is_hidden %}
            {{ field }}
        {% else %}
        {% if field.errors %}{{ field.errors }}{% endif %}
            <p
            {% if field.errors %} class="error"{% endif %}
            {% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>
            </p>
        {% endif %}
    {% endfor %}
    <textarea id="id_comment" rows="1" cols="60" name="comment" class='id_comment'></textarea>
    <p class="submit">
        <input type="submit" name="post" class="submit-post blue comment_submit" value="{% trans "Comment" %}" id="button" style="float:right;margin-top:-6px;margin-bottom:4px;"/>
    </p>
    <div class="clearfix"></div>
    </form>

</div>

And then my jQuery looks as follows

<script type="text/javascript">
    $(document).ready(function(){
        // Here it runs a simple each statement to apply a unique ID to each comment-form
        $('.comment-form').each(function(){
            var element = $(this).find('#id_object_pk').val();
            $('#commentload').attr('id','commentload'+element);
            $(this).attr('name', element);
            $(this).attr('id', element);
            $(this).find('#button').attr('id', element);
            $(this).find('#id_content_type').attr('id', 'id_content_type' + element);
            $(this).find('#id_timestamp').attr('id', 'id_timestamp' + element);
            $(this).find('#id_security_hash').attr('id', 'id_security_hash' + element);
            $(this).find('#id_comment').attr('id', 'id_comment' + element); 
        });

        $(".comment_submit").live("click",function() {
            var ID = $(this).attr('id');

            var content_type = $('#id_content_type'+ID).val();
            var timestamp = $('#id_timestamp'+ID).val();
            var security_hash = $('#id_security_hash'+ID).val();
            var comment = $('#id_comment'+ID).val();
            var dataString = 'content_type='+ content_type +'&timestamp='+ timestamp +'&security_hash=' + security_hash + '&comment=' + comment + '&object_pk=' + ID;

            if (comment=='') {
                alert('Please enter a comment');
            } else {
                $('#id_comment'+ID).val('').addClass("greyout");
                $.ajax({
                    type: "POST",
                    url: "{% comment_form_target %}",
                    data: dataString,
                    cache: false,
                    success: function(html){
                        $("#commentload"+ID).append(html);
                        $('#id_comment'+ID).val('').removeClass("greyout").focus();
                    }
                });
            }
            return false;
        });
    });
</script>

HTML OUTPUT the difference between the forms obviously the ID for each one

<div id="wall-comments">
    <div class="comments">
    <form action="/comments/post/" method="post" class="comment-form" id="114">
        <input type="hidden" name="content_type" value="wall.post" id="id_content_type114">
        <input type="hidden" name="object_pk" value="114" id="id_object_pk">
        <input type="hidden" name="timestamp" value="1291370494" id="id_timestamp114">
        <input type="hidden" name="security_hash" value="2d208d05d725528dfef940d8a5b520362faa3317" id="id_security_hash114">
        <textarea id="id_comment114" rows="1" cols="60" name="comment" class="id_comment" style="height: 24px; overflow-x: hidden; overflow-y: hidden; "></textarea>
        <p class="submit">
            <input type="submit" name="post" class="submit-post blue comment_submit" value="Comment" id="114" style="float:right;margin-top:-6px;margin-bottom:4px;">
        </p>
        <div class="clearfix"></div>
    </form>
    </div>
</div>
  • 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-18T08:48:01+00:00Added an answer on May 18, 2026 at 8:48 am

    You are binding the click function too many times. You only should call .live(“click”, function() {}); Once per page load. Or else you should use die() to unbind the functions before calling live() again.

    I still think this is the answer. Change the click .live call to be:

    $(".comment_submit").die("click").live("click",function() {
        var ID = $(this).attr('id');
    
        var content_type = $('#id_content_type'+ID).val();
        var timestamp = $('#id_timestamp'+ID).val();
        var security_hash = $('#id_security_hash'+ID).val();
        var comment = $('#id_comment'+ID).val();
        var dataString = 'content_type='+ content_type +'&timestamp='+ timestamp +'&security_hash=' + security_hash + '&comment=' + comment + '&object_pk=' + ID;
    
        if (comment=='') {
            alert('Please enter a comment');
        } else {
            $('#id_comment'+ID).val('').addClass("greyout");
            $.ajax({
                type: "POST",
                url: "{% comment_form_target %}",
                data: dataString,
                cache: false,
                success: function(html){
                    $("#commentload"+ID).append(html);
                    $('#id_comment'+ID).val('').removeClass("greyout").focus();
                }
            });
        }
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I have modified my code to While taking input form STDIN, I moved
I have built ICS source using make -j4, then I have modified the Music
i use Telerik Demo Sheduler as my base. I have modified data loading like
I have modified a slider script to mimic ebay's slider on home page. I
I have modified the Nerd Dinner application to allow editing of child records by
I have modified my MOSS 2007 configuration to query a given target AD successfully.
I have modified a working Windows service that had always been starting beforehand. After
I have modified a website with a redirection to a single page: RewriteCond %{REQUEST_FILENAME}
I have modified unobtrusive validation script to replace error messages with qtips. To do
I have cloned a remote SVN repository with git-svn. I have modified a pom.xml

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.