views:

55

answers:

3

I know I can change the attribute checked to checked, but i need to actually "click" the checkbox to fire off a live() (jQuery) click event. I know I can also make it a function, but this would just be a lot cleaner and less code, if possible.

Oh, and FYI:

$('.modal-form [name='+json[0].owners[x].name+']').click();

Doesn't work. It checks em, but doesnt actually "click" them to where jQuery fires the live() event

Here's the AJAX call if anyone is interested:

$('.agenda-modal input[type=checkbox]:not([name="emergency-item"])').live('click',function(){
        iid = $('.agenda-modal').attr('data-defaultitemid');
        the_type = $(this).parent().parent().attr('id');
        checked_item = $(this).val();

        if($(this).attr('checked')){
            if(the_type == 'the-elected-list'){
                $livepreview.agenda({
                    action:'update',
                    type:'owner',
                    id:iid,
                    owner:checked_item
                });
            }
            else if(the_type == 'the-bureau-list'){
                $livepreview.agenda({
                    action:'update',
                    type:'bureau',
                    id:iid,
                    bureau:checked_item
                });
            }
        }
        else{
            $livepreview.agenda({
                action:'get',
                type:'item',
                id:iid,
                callback:function(json){
                    if(the_type == 'the-elected-list'){
                        for(x in json[0].owners){
                            if(json[0].owners[x].name == checked_item){
                                $livepreview.agenda({
                                    action:'delete',
                                    type:'owner',
                                    id:json[0].owners[x].item_owner_id
                                });
                            }
                        }
                    }
                    else if(the_type == 'the-bureau-list'){
                        for(x in json[0].bureaus){
                            if(json[0].bureaus[x].name == checked_item){
                                $livepreview.agenda({
                                    action:'delete',
                                    type:'bureau',
                                    id:json[0].bureaus[x].item_bureau_id
                                });
                            }
                        }
                    }
                }
            });
        }
    });
A: 

This will 'click' the checkbox. I'm not positive if it will fire an event bound with live().

$('#myCheck').click();
g.d.d.c
A: 

please include an example. you are most likely not finding the right element by making a complex expression. tone it down.

var el = $('.modal-form [name='+json[0].owners[x].name+']')
alert( el.length )

Then you can .trigger('click') it. Make sure the event handler is bound/set.

meder
For each item I get a "1" returned in the alert. So, if I have two "owners" selected, i get 2 alerts each with "1" returned.
Oscar Godson
please include an example
meder
A: 

Obviously I don't know your code base, but I really wonder whether calling a function by faking UI interaction would be "a lot cleaner". It might be less code, but it sounds very fragile to me. What happens when the UI is redesigned? Or another developer modifies the live() event handler without realizing that your code is implicitly using it as well? Moving the code into a separate function makes it both more legible and more robust (and probably not significantly longer).

Annabelle