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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:34:02+00:00 2026-05-27T21:34:02+00:00

I’m building a site for someone and on the Admin side there is a

  • 0

I’m building a site for someone and on the Admin side there is a “Manage Users” page to manage the website’s users. Here is my two functions to suspend and unsuspend (and for the alert):

var admin = {
    alert: (function(msg,dur) {
        if(!dur || dur == null) {
            dur = 1500;
        }
        $('#alert_box2').remove();
        $('body').append('<div id="alert_box2" style="width: 100%; height: 9px; top: -17px; left: 0; position: absolute; text-align: center; z-index: 5;"><div id="alert_box_inner2"></div></div>');
        $('#alert_box2').show(0, function() {
            if(dur!=='none') {
                $('#alert_box_inner2').html(msg).stop(true, true).fadeIn(800).delay(dur).fadeOut(800, function() {
                    $('#alert_box2').remove();
                });
            }
            else {
                $('#alert_box_inner').html(msg).show();
            }
        });
    }),
    suspendUser: (function(id) {
        admin.alert('Please wait...',20000);
        $.get('user_more_actions.php?action=suspend&nolightbox=1&id='+id, function(data,textStatus) {
            setTimeout(function() {
                if(textStatus=='success') {
                    if(data.indexOf('suspended') > -1) {
                        name = data.replace('suspended ','');
                        admin.alert(name+' is now suspended.',2500);
                        $('#status_'+id).html('<strong style="color: red;">Suspended</strong>');
                        $('#suspend_'+id).attr('id','unsuspend_'+id).text('Unsuspend').removeClass('suspend').addClass('unsuspend');
                    }
                    else {
                        admin.alert('Sorry, there was an error. <span class="s_link" onclick="$(\'#suspend_'+id+'\').click();">Try again</a>','none');
                    }
                }
                else {
                    admin.alert('Sorry, there was an error. <span class="s_link" onclick="$(\'#suspend_'+id+'\').click();">Try again</a>','none');
                }
            }, 500);
        });
    }),
    unsuspendUser: (function(id) {
        admin.alert('Please wait...',20000);
        $.get('user_more_actions.php?action=unsuspend&nolightbox=1&id='+id, function(data,textStatus) {
            setTimeout(function() {
                if(textStatus=='success') {
                    if(data.indexOf('unsuspended') > -1) {
                        name = data.replace('unsuspended ','');
                        admin.alert(name+' is no longer suspended.',2500);
                        $('#status_'+id).html('<strong style="color: green;">Active</strong>');
                        $('#unsuspend_'+id).attr('id','suspend_'+id).text('Suspend').removeClass('unsuspend').addClass('suspend');
                    }
                    else {
                        admin.alert('Sorry, there was an error. <span class="s_link" onclick="$(\'#unsuspend_'+id+'\').click();">Try again</a>',20000);
                    }
                }
                else {
                    admin.alert('Sorry, there was an error. <span class="s_link" onclick="$(\'#unsuspend_'+id+'\').click();">Try again</a>',20000);
                }
            }, 500);
        });
    })
};

And the code that triggers the functions when a Suspend or Unsuspend link is clicked:

$('.suspend').each(function() {
    $(this).live('click', function(e) {
        e.preventDefault();
        var id = $(this).attr('id').replace('suspend_', '');
        admin.suspendUser(id);
    });
});
$('.unsuspend').each(function() {
    $(this).live('click', function(e) {
        e.preventDefault();
        var id = $(this).attr('id').replace('unsuspend_', '');
        admin.unsuspendUser(id);
    });
});

Everything is working ok, except when I click again it messes up. When a Suspend link is clicked, it changes to Unsuspend (and changes the ID). But then if I click Unsuspend it doesn’t work, and it is calling the admin.suspend() function instead of admin.unsuspend() (and the ID isn’t being passed so the name isn’t displayed):

screenshot

When the class and the ID is changed it should call either the admin.suspend(id_here) or admin.unsuspend(id_here); but it isn’t.

Does anyone know why this is happening? Thanks in advance and I’m sorry that this post is long.

  • 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-27T21:34:03+00:00Added an answer on May 27, 2026 at 9:34 pm

    I’ve fiddled with it. Hope this helps:http://jsfiddle.net/wKGKu/

    Update: After reading your concerns for .each, I’ve updated the code to demonstrate it isn’t needed: http://jsfiddle.net/wKGKu/2/

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm making a simple page using Google Maps API 3. My first. One marker

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.