I have a button that I click and I want the fancybox to load whatever content is needed depending on some checkboxes that I can check. Those checkboxes will alter the value of the url that needs to be displayed in the iframe within the fancybox.
So far I can get it to work once, when I change again the checkboxes I will see the url change on the html but the fancybox won't pop at all.
Here is my button and the link for the fancybox:
<button type="button" title="Compare" class="button">Compare</button>
<a class="comparefancy" style="display:none;" href="#"></a>
Here is what happens when I click the button:
jQuery(document).ready(function() {
jQuery('.button').click(function(){
var i=0;
var prdString="";
var prdString = jQuery.map(jQuery(':checkbox:checked'), function(n, i){
return n.value;
}).join(',');
var url='<?php echo Mage::getUrl('catalog/product_compare/index').'items/'; ?>'+ prdString + '/uenc/';
jQuery('.comparefancy').attr('href', url);//this works all the time
jQuery('.comparefancy').fancybox(); //this will only work the first time
jQuery('.comparefancy').trigger('click');
});
});
I've tried the beforeLoad method hinted at on some similar answers but it didn't work for me.
Edit: After testing this more I removed the display none from the link and made it visible and then did the following:
- checked my checkboxes then clicked the button: the first fancybox loads just fine
- checked other checkboxes, then clicked the button: the link will change its href but the fancy won't load.
- click the link manually and then the fancybox loads the new url
So the problem is my trigger click function then? wtf?