OK, I think that my problem had to do with the fact that I'm using the
livequery plugin to handle rebinding after new rows get created (I
have not included this part of my code).

I was able to get what I needed using the following code:

//deactivate activate click handler
var destroy = function() {
         $(this).unbind('toggle').unbind('click');
};

// the following toggle function changes various things about the
image clicked and the table row it is in
// this part has always worked fine

var init = function() {
        $(this).toggle(function(e){
                var $this = $(this);
                //alert('deactivating');
                $(this).attr("src","images/btnReactivate.gif")
                        
$(this).parents('tr:eq(0)').css({"background-image":"url(images/
deactivated_SlantBar.jpg)"});
                        $(this).parents('tr:eq(0)').find("input[name
$='useThisRecord']").val(0);
                        $(this).parents('tr:eq(0)').find('input').css("border-
width","0px").attr("readonly","true");
                        $(this).parents('tr:eq(0)').find('input').css({ "border-
width":"0px","color":"#909090"}).attr("readonly","true");
                }, function(e) {
                //alert('reactivating');
                        $(this).parents('tr:eq(0)').css('background-image', '');
                        $(this).parents('tr:eq(0)').find('input').css({"border-
width":"1px","color":"black"}).removeAttr("readonly");
                        $(this).parents('tr:eq(0)').find("input[name
$='useThisRecord']").val(1);
                        //alert($(this).parents('tr:eq(0)').find("input[name
$='useThisRecord']").val());
                        $(this).attr("src","images/btnDeactivate.gif")

});
};

$("img.active_toggle").livequery(init,destroy);

// following is the part that I was struggling with
// the function looks at each image when the page loads
// checks the associated input field to see if its value is false
// and if so, triggers a click (and hence the toggle for that image
and row)

$("img.active_toggle").each(function(index,obj){
myUseThisRecord = (index+1) + "useThisRecord";
//alert(myUseThisRecord);
        if ($('input[name=' + myUseThisRecord + ']').val()=="False")
        {alert(index);
                $(obj).livequery(function(event)
                {
                $(obj).trigger("click");
        });
        }
});

Thanks for the help!

Reply via email to