Resetting setTimeout object if exists
<p>When somebody clicks my checkboxes, from a long list of checkboxes, I want to show the number of selected checkboxes in a little popup element. My problem is, the little popup element should disappear 5 seconds after the <strong><em>last</em></strong> click, which is OK for one checkbox being clicked, but if I quickly check 5 boxes, the timer is still set on the first box, resulting in the popup element disappearing too quickly.</p>

<p>As you can see in my function, I've tried using the <code>clearTimeout(timeoutName)</code> function but have experienced some troubles applying it. The console log states that the <code>clearTimeout(timeoutName)</code> is undefined, which I can understand: the setTimeout hasn't even started yet.</p>

<p>How can I check that the timer exists before I clear it? Or is this really not the best method? When a checkbox is checked (this function runs) there could be a timer running but sometimes there could not be.</p>

<pre><code>$('.name_boxes').live('click', function() {
    var checked_count = $('.name_boxes:checked').length;
    // other stuff

    clearTimeout(hide_checked_count_timer); // if exists????????

    $(".checked_count").hide();
    $(".checked_count").text(checked_count+" names selected");
    $(".checked_count").show();

    hide_checked_count_timer = setTimeout(function() {
        $(".checked_count").hide();
    },5000);
});
</code></pre>

<p>Any help gratefully received...</p>
