calling different URL based on button value using jquery-Collection of common programming errors

I have a button that calls a CFM page and it needs to pass a value depending on whether the user is activating or deactivating a record from the database. I’m struggling with how to pass the active/inactive value into jQuery. Below is the code I’m using, which only works one-way, that is from active to inactive.


$(document).ready(function() {

    $("#IsActive_1").click(function() {

    //cache the status div
        var status = $("#status");

        //let the user know the record is being updated
        status.html("updating status...");

    $("#IsActive_1").html('activate');

        //the status variable needs to be dynamic
        $.get("updateStatus.cfm?status=inactive", {}, function(res,code) {
        //show the result in plain HTML
        status.html(res);
    });

    });

});



deactivateactivate

Lastly, I would like to change the text displayed on the button to activate/deactivate based on the proper condition (activate after clicking deactivate and viceversa).

TIA

  1. You can add an attr to the button, and based on it, send the variable.

    Deactivate
    
    
        $("#IsActive_1").click(function() {
              var x = $(this);
              var isActive = x.attr('checked') != undefined;
              if (isActive)
                x.removeAttr('checked');
              else
                x.attr('checked', 'checked');
            //cache the status div
                var status = $("#status");
    
                //let the user know the record is being updated
                status.html("updating status...");
    
                 x.html(isActive ? 'Activate' : 'Deactivate');
    
                //the status variable needs to be dynamic
                $.get("updateStatus.cfm", { status : isActive ? 'inactive' : 'active' }, function(res,code) {
                //show the result in plain HTML
                status.html(res);
            });
    
            });
    

Originally posted 2013-11-09 21:39:01.