Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

javascript question regarding related products
 
Emma86
Sr. Member
 
Total Posts:  110
Joined:  2009-03-03
 

Hiya all,

I have some related products assigned to some of my products.. I want the checkboxes checked when the page loads… you cant just change the .phtml file for related products to checked within the checkbox tag as a javascript runs when you select one of the checkboxes that adds it to the data to be submitted…

however magento has a built in ‘select all’ link that I maybe able to use to do this with some help from a js guru if there are any here.. when clicking select all’ link the following javascript is ran ...

<script type="text/javascript">

<!--
$$(
'.related-checkbox').each(function(elem){
    Event
.observe(elem'click'addRelatedToProduct)
});

var 
relatedProductsCheckFlag false;
function 
selectAllRelated(txt){
    
if (relatedProductsCheckFlag == false{
        
$$('.related-checkbox').each(function(elem){
            elem
.checked true;
        
});
        
relatedProductsCheckFlag true;
        
//txt.innerHTML="<?php echo $this->__('unselect all') ?>";
    
else {
        
$$('.related-checkbox').each(function(elem){
            elem
.checked false;
        
});
        
relatedProductsCheckFlag false;
        
//txt.innerHTML="<?php echo $this->__('select all') ?>";
    
}
    addRelatedToProduct
();
}

function addRelatedToProduct(){
    
var checkboxes = $$('.related-checkbox');
    var 
values [];
    for(var 
i=0;i<checkboxes.length;i++){
        
if(checkboxes[i].checkedvalues.push(checkboxes[i].value);
    
}
    
if($('related-products-field')){
        
$('related-products-field').value values.join(',');
    
}
}
//-->
</script>

As you can see from that, the function addRelatedToProduct is the one that sets them all checked.. so I tried putting this code on the page..

window.onload addRelatedToProduct();

Im sure you can see what im going for here wink

so now when page loads, it runs addRelatedToProduct() however the checkboxes dont get ticked, and nothing gets added to the pending form data. I can confirm the function does run on page load as I outputted a test message using alert within the function.

Anyone have any ideas on this?

many thanks
emmas

 
Magento Community Magento Community
Magento Community
Magento Community
 
Emma86
Sr. Member
 
Total Posts:  110
Joined:  2009-03-03
 

bumps smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top