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 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

Ask A Question

Stats

  • Questions 191k
  • Answers 191k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Do you have the tab page name or the tab… May 12, 2026 at 6:12 pm
  • Editorial Team
    Editorial Team added an answer You could use the inbuilt Stopwatch class to "Provides a… May 12, 2026 at 6:12 pm
  • Editorial Team
    Editorial Team added an answer No, it's not possible in a text area or a… May 12, 2026 at 6:12 pm

Related Questions

I'm using the Zend framework and the openid selector from http://code.google.com/p/openid-selector/ - however I
I'm working on a relatively simple website with (currently) a single resource. I have
I have a reasonably large project at work that I've inherited. It's an ASP.NET
I have the task to build a web-site for a smaller non-profit organization. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.