How to update the right span?
<p>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:</p>

<pre><code>&lt;script src="/js/MicrosoftAjax.js" type="text/javascript" language="javascript"&gt;&lt;/script&gt;

&lt;script type="text/javascript" language="javascript"&gt;

    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";
    }

&lt;/script&gt;
</code></pre>

<p>And this is the reporting link:</p>

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

Other posts ...
</code></pre>

<p>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?</p>

<p>Many thanks</p>
