views:

49

answers:

2

I'm trying to get a jQuery ColorBox window to open when a checkbox is checked and I'm having some issues figuring it out. First of all, can it be done with out making major changes to the colorbox.js file? If so, can you help steer me in the right direction on how to go about this?

Thanks in advance.

A: 

I'm not exactly sure what you are trying to do, but with the information you've given, could you not bind the focus event on the checkbox to a function that opens an instance of ColorBox?

$("selectorForCheckbox").bind("focus", function(e) {
    // initiate colorbox here. 
});
Alex
Let me know if my answer is what you are looking for. Let me know if this is not what you want too.
Alex
+1  A: 

Try this (demo)

HTML

<input type="checkbox" value="http://s3.tinypic.com/546ut2_th.jpg" title="image"> Image

Script

$(':checkbox').bind('click', function() {
    if ($(this).is(':checked')) {
        $.colorbox({
            photo: true,
            href: $(this).val()
        });
    }
})
fudgey
That's actually really close to what I'm looking for. Thanks! The only thing I'm still trying to figure out is how do I specify the colorbox popup only to open when a certain checkbox is checked? For example, I have a checkbox called "the_event", I need it to open when that is checked. Thanks again.
mike
Just adjust the jQuery selector... try `$('input#the_event').bind(...)`. The above script was written to extract out the image src from the input box value, so you can also use a class that will open the colorbox. Something like `$('input.openColorBox')` would work too.
fudgey
Got it working now, thanks!
mike