Subesh Pokhrel

Magento Developers Blog

MageNote - Select First Options of the Configurable Product Options on Load

Here’s the script on Gist.
/**
Add following lines on view.phtml. Done for the case of Color and Size.
This will not work for all but get the idea!
*/
<?php
// Making the first selection of the color selected when only one
if ($_product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE):?>
<script>
document.observe("dom:loaded", function() {
var options = $$('#attribute272 option'); //#first attribute ID
var len = options.length;
if (len == 2) {
$('attribute272').options[1].selected = true;
spConfig.fillSelect($('attribute525')); //Second attribute ID
$('attribute525').disabled = false;
}
});
</script>
<?php endif;?>
view raw view.phtml hosted with ❤ by GitHub