On Thu, Dec 11, 2008 at 10:30 AM, heohni
<[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> this is my first post, I hope I do everything right!

Most of us only post questions here when we're doing something wrong ;-)

> For the moment I toogle only active into inactive.
> Because I do not know how to send 2 information (user's ID and the
> current status ID) to my jquery function.

Do you mean from the PHP script? What is it returning?

Anyway, I once did something quite similar.

<div class="statusimg inactive" id="{$hersteller_daten[her].her_id}"></div>

CSS:

.statusimg
{
        width: 15px; height: 15px;
        cursor: pointer;
        background: transparent url(/img/status.gif) 0 0 no-repeat;
}
.statusimg.inactive { background-position: 15px 0; }
.statusimg.active { background-position: 30px 0; }
.statusimg.no_login { background-position: 45px 0; }

Where status.gif is a 60px x 15px image divided into 4 states. The
square at far left (0 0) represents the "loading" state when you do
your AJAX call. This could be animated in some way.

@   |    inactive   |   active    |   no_login

I don't think you should need to send the status to the server because
that information should already be there. All your script should need
to know is the ID. With that, it should be able to look up the current
status in the session, DB, etc.

When the page first loads, you should set the 2nd class on each div
accordingly (ie. "statusimg inactive", "statusimg active", etc.)
That's important because, otherwise, you'll have a bunch of twirling
animations.

Something like this:

$(document).ready(function(){
        $('div.statusimg').click(function() {
                var status = this;
                var her_id = status.id;
                
                /* remove all 2nd classes to reveal default state (eg. 
animation)
                 */
                $(status).removeClass('active', 'inactive', 'no_login');
                
                $.ajax({
                        type: "POST",
                        url: "/admin/ajax_toogle_manufacturer_status.php",
                        data: "her_id=" +her_id,
                        success: function(msg){
                                /* get the new status from the returned data
                                */
                                status.addClass(the_new_status);
                        }
                });
        })
});

How you get the new status className depends on what your PHP script returns.

Reply via email to