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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:50:53+00:00 2026-05-11T16:50:53+00:00

On my forum-based website, I have a link below every post for reporting spam

  • 0

On my forum-based website, I have a link below every post for reporting spam or abuse. Whenever this link is clicked, a web service is called on the server, when the call returns, the span containing the link (see the code below) is updated with something like ‘Post reported’ or if an error occurs it shows something like ‘An error occurred while reporting the post’, this is the javascript code:

<script src="/js/MicrosoftAjax.js" type="text/javascript" language="javascript"></script>

<script type="text/javascript" language="javascript">

    var spanToUpdate;

    function ReportPost(updateSpan, postID)
    {
      if (confirm("Are you sure you want to report this post as spam or abuse?"))
      {
        spanToUpdate = updateSpan;
        var proxy = SiteWS.ReportPost(postID, onReportPostSuccess, onReportPostFailure);
      }
    }

    function onReportPostSuccess(sender, e)
    {
      spanToUpdate.innerHTML = "Post reported";
    }

    function onReportPostFailure(sender, e)
    {
      spanToUpdate.innerHTML = "An error occurred while reporting the post";
    }

</script>

And this is the reporting link:

<div class="post">
  <p>post text here</p>
  <span><a href="#" onclick="ReportPost(this.parentNode, <%= post.ID %>);return false;" title="Report spam or abuse">Report Post</a></span>
</div>

Other posts ...

As you can see, I use a variable, spanToUpdate, to hold a reference to the span that contains the reporting link, which means that if the user reports another post (ie. clicks another reporting link) before the call returns, the span of the last post will be updated twice and the previous one won’t be updated at all, is there any workaround for this?

Many thanks

  • 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-11T16:50:53+00:00Added an answer on May 11, 2026 at 4:50 pm

    You can use anonymous functions and closures for that.

    function ReportPost(updateSpan, postID) {
      if (confirm("Are you sure you want to report this post as spam or abuse?")) {
        var proxy = SiteWS.ReportPost(
          postID,
          function(sender,e) {updateSpan.innerHTML = "Post reported" },
          function(sender,e) {updateSpan.innerHTML = "An error occurred while reporting the post" }
        );
      }
    }

    edit:

    hmm .. just wondering, will updateSpan be referring to the same span when the anonymous method is called? – Waleed Eissa

    Yes, that’s the magic of closures. Try this little example:

    <head>
      <script>
        function foo()
        {
          bar(1, 100);
          bar(2, 150);
          bar(3, 200);
          bar(4, 250);
          bar(5, 300);
          document.getElementById("div1").innerHTML += "foo() is done. ";
          return;
        }
        function bar(val, timeout) {
          window.setTimeout(
            function() {
              document.getElementById("div1").innerHTML += " " + val + " ";
            },
            timeout
          );
        }
      </script>
    </head>
    <body>
      <button onclick="foo()">click</button>
      <div id="div1"></div>
    </body>

    You will see that each time the anonymous function is called it has preserved “its own” value of val from the time/context when bar() was called.

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

Sidebar

Related Questions

I have a vanilla forum based forum website. Currently customizing it. Before few days
I have website based on Umbraco 5. I have installed contact form plugin (http://cultivjupitercontact.codeplex.com/).
I'm building a simple web based forum application. I want to allow users to
I have created a forum board app, based on YAML schema found in 'real
I have a form on my website (based on Drupal), and I've added a
I have a PHP based website, with database connections, form processing, etc, that I
I have been lurking for a long time on this forum and I found
So I have a really simple form on a website that's entirely AJAX based
I have built a website based on Google App Engine. It includes ten models,
I have a classifieds website, where anyone (no need for login currently) can post

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.