Set default value on configurable drop down in magento











up vote
0
down vote

favorite
2












I have a Configurable Product with 3 Options - here is what the drop down menu looks like on the product page.



Bundle Deals            

* Required Fields
Choose an Option...
- Single Product £10
- 5 Product Bundle £50
- 10 Product Bundle £100


Default value on page load is £10.00 but if I hit add to cart it flags up with - * Required Fields & user is prompted to select an option from the drop down.



By default I would like the drop down menu to load with - Single Product £10 as the default value.



Hope that all makes sense? I can't find this functionality in the Magento version 1.9 CE, which I am using



FINAL EDIT >> thanks to everyone for helping - got a fix - Very glad! visit link.. similar to a suggestion here but something in the code seemed to work for me



http://iamvikram.com/magento-remove-choose-an-option-from-configurable-products-dropdown/



A thank you msg has been mailed :)










share|improve this question
















bumped to the homepage by Community 21 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Might have some luck on magento.stackexchange.com
    – Andy
    Jul 24 '14 at 12:18










  • glad that you have it sorted out. I also like to remove the Choose an Option from the drop down cause it's useless if the option is required.
    – William Tran
    Jul 24 '14 at 23:25















up vote
0
down vote

favorite
2












I have a Configurable Product with 3 Options - here is what the drop down menu looks like on the product page.



Bundle Deals            

* Required Fields
Choose an Option...
- Single Product £10
- 5 Product Bundle £50
- 10 Product Bundle £100


Default value on page load is £10.00 but if I hit add to cart it flags up with - * Required Fields & user is prompted to select an option from the drop down.



By default I would like the drop down menu to load with - Single Product £10 as the default value.



Hope that all makes sense? I can't find this functionality in the Magento version 1.9 CE, which I am using



FINAL EDIT >> thanks to everyone for helping - got a fix - Very glad! visit link.. similar to a suggestion here but something in the code seemed to work for me



http://iamvikram.com/magento-remove-choose-an-option-from-configurable-products-dropdown/



A thank you msg has been mailed :)










share|improve this question
















bumped to the homepage by Community 21 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Might have some luck on magento.stackexchange.com
    – Andy
    Jul 24 '14 at 12:18










  • glad that you have it sorted out. I also like to remove the Choose an Option from the drop down cause it's useless if the option is required.
    – William Tran
    Jul 24 '14 at 23:25













up vote
0
down vote

favorite
2









up vote
0
down vote

favorite
2






2





I have a Configurable Product with 3 Options - here is what the drop down menu looks like on the product page.



Bundle Deals            

* Required Fields
Choose an Option...
- Single Product £10
- 5 Product Bundle £50
- 10 Product Bundle £100


Default value on page load is £10.00 but if I hit add to cart it flags up with - * Required Fields & user is prompted to select an option from the drop down.



By default I would like the drop down menu to load with - Single Product £10 as the default value.



Hope that all makes sense? I can't find this functionality in the Magento version 1.9 CE, which I am using



FINAL EDIT >> thanks to everyone for helping - got a fix - Very glad! visit link.. similar to a suggestion here but something in the code seemed to work for me



http://iamvikram.com/magento-remove-choose-an-option-from-configurable-products-dropdown/



A thank you msg has been mailed :)










share|improve this question















I have a Configurable Product with 3 Options - here is what the drop down menu looks like on the product page.



Bundle Deals            

* Required Fields
Choose an Option...
- Single Product £10
- 5 Product Bundle £50
- 10 Product Bundle £100


Default value on page load is £10.00 but if I hit add to cart it flags up with - * Required Fields & user is prompted to select an option from the drop down.



By default I would like the drop down menu to load with - Single Product £10 as the default value.



Hope that all makes sense? I can't find this functionality in the Magento version 1.9 CE, which I am using



FINAL EDIT >> thanks to everyone for helping - got a fix - Very glad! visit link.. similar to a suggestion here but something in the code seemed to work for me



http://iamvikram.com/magento-remove-choose-an-option-from-configurable-products-dropdown/



A thank you msg has been mailed :)







javascript php magento configurable-product






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 21 '15 at 10:23









McNab

6,30732446




6,30732446










asked Jul 24 '14 at 12:17









dan_code89

20211




20211





bumped to the homepage by Community 21 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 21 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Might have some luck on magento.stackexchange.com
    – Andy
    Jul 24 '14 at 12:18










  • glad that you have it sorted out. I also like to remove the Choose an Option from the drop down cause it's useless if the option is required.
    – William Tran
    Jul 24 '14 at 23:25


















  • Might have some luck on magento.stackexchange.com
    – Andy
    Jul 24 '14 at 12:18










  • glad that you have it sorted out. I also like to remove the Choose an Option from the drop down cause it's useless if the option is required.
    – William Tran
    Jul 24 '14 at 23:25
















Might have some luck on magento.stackexchange.com
– Andy
Jul 24 '14 at 12:18




Might have some luck on magento.stackexchange.com
– Andy
Jul 24 '14 at 12:18












glad that you have it sorted out. I also like to remove the Choose an Option from the drop down cause it's useless if the option is required.
– William Tran
Jul 24 '14 at 23:25




glad that you have it sorted out. I also like to remove the Choose an Option from the drop down cause it's useless if the option is required.
– William Tran
Jul 24 '14 at 23:25












4 Answers
4






active

oldest

votes

















up vote
0
down vote













Copy below file in your local



/app/design/frontend/default/mytheme/template/catalog/product/view/type/options/configurable.phtml


<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>


It shows 'Choose an Option...' as a default value



You can change it like below to simply select the first real element in your select:



$$('#attribute525 option')[1].selected = true;


Check with your attributeid. The above is just an example.






share|improve this answer























  • Thanks @Slimshadddyyy - Cant get this to work.. If I change the text from "Choose an Option..." to "Choose a Product..." Still the old msg Choose an Option comes up in the drop box.. I have refreshed cache & indexes.. Maybe a different file is actioning the function.. ? I added the '$$('#attribute525 option')[1].selected = true;' - still lookin at this
    – dan_code89
    Jul 24 '14 at 13:34










  • @dan_code89 on your product page, inspect the dropdown and check the attributeid of select. For me its attribute502. For you it could be something else. Pass that attributeid
    – Slimshadddyyy
    Jul 25 '14 at 4:11


















up vote
0
down vote













Navigate to Catalog->Attributes->Manage Attributes in your magento admin and search for your attribute.



Click to edit and select No to Values required.



Hope it will work.



JQuery to default select first value is -



jQuery('#attribute135>option:eq(1)').attr('selected', true);





share|improve this answer























  • we need to select the first option as default selected and not to by pass validation
    – Slimshadddyyy
    Jul 24 '14 at 12:25












  • Alright, so you are having 3 attributes and you want to select first option as default selected for all 3 attributes ?
    – TBI
    Jul 24 '14 at 12:29










  • Thanks SlimShadddyyy - I tried that - I still get flagged for Required fields.
    – dan_code89
    Jul 24 '14 at 12:30










  • What if you just remove the Please Select message from Custom Option Dropdown on Magento Product View and making the first option as default selected ?
    – Slimshadddyyy
    Jul 24 '14 at 12:32












  • Yeah - If it can select the first attribute as default I would be very happy :) Or if I can turn off the validation (Required Fields) that would also be great - But I think configureable products are always Required..
    – dan_code89
    Jul 24 '14 at 12:32


















up vote
0
down vote













This could get tricky if you have 2+ options (it's confusing but what you describe above is 1 option with 3 selection), says Color and Size. Assuming Color is the first Option, Size's selection will be updated once Color is selected.



For example, you have a shirt available in Red in size (S,L) and Blue in size (M,L), once you select Blue, Magento observe the event 'onChange' of the Color option and update the Size option to M, L.



This is what I would do to get it done correctly in PrototypeJS:



<script type='text/javascript>
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);

document.observe('dom:loaded', function() {
var el = $('attribute<?php echo $_attribute->getAttributeId() ?>');
el.selectedIndex = 1;
el[0].remove();
if ("createEvent" in document) {
var ev = document.createEvent("HTMLEvents");
ev.initEvent("change", false, true);
el.dispatchEvent(ev);
} else {
el.fireEvent("onchange");
}
</script>


in configurable.phtml, please note the fireEvent / dispatchEvent.
el[0].remove will get rid of "Select an option.."



This is the least intrusive method that I know of






share|improve this answer























  • Have tried this @William Tran - sorry I couldnt get it working.. error msgs... Can you explain it a bit more & the fireEvent?. I am not a JavaScript writer.. Just HTML & CSS are my main thing.. Would be Much Obliged for a solution here :/
    – dan_code89
    Jul 24 '14 at 17:23












  • can you let me know what kind of error message?
    – William Tran
    Jul 24 '14 at 22:28










  • My answer is for configurable product with one option: you have to populate $_attribute before getting to the script.
    – William Tran
    Jul 25 '14 at 1:16




















up vote
0
down vote













Open appdesignfrontend[your package][your theme]templatecatalogproductviewtypeoptionsconfigurable.phtml


Now add the below java-script code after :-



var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);


function fireEvent(element,event){

if (document.createEventObject){

// dispatch for IE

var evt = document.createEventObject();

return element.fireEvent('on'+event,evt)

}

else{

// dispatch for firefox + others

var evt = document.createEvent("HTMLEvents");

evt.initEvent(event, true, true ); // event type,bubbling,cancelable

return !element.dispatchEvent(evt);

}

}

Event.observe(window, 'load', function() {

spConfig.settings[0].selectedIndex = 1;

obj = spConfig.settings[0]; // this grabs the first select item

Event.observe(obj,'change',function(){});

fireEvent(obj,'change'); // this simulates selecting the first option, which triggers

spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
});





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24933460%2fset-default-value-on-configurable-drop-down-in-magento%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Copy below file in your local



    /app/design/frontend/default/mytheme/template/catalog/product/view/type/options/configurable.phtml


    <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
    <option><?php echo $this->__('Choose an Option...') ?></option>
    </select>


    It shows 'Choose an Option...' as a default value



    You can change it like below to simply select the first real element in your select:



    $$('#attribute525 option')[1].selected = true;


    Check with your attributeid. The above is just an example.






    share|improve this answer























    • Thanks @Slimshadddyyy - Cant get this to work.. If I change the text from "Choose an Option..." to "Choose a Product..." Still the old msg Choose an Option comes up in the drop box.. I have refreshed cache & indexes.. Maybe a different file is actioning the function.. ? I added the '$$('#attribute525 option')[1].selected = true;' - still lookin at this
      – dan_code89
      Jul 24 '14 at 13:34










    • @dan_code89 on your product page, inspect the dropdown and check the attributeid of select. For me its attribute502. For you it could be something else. Pass that attributeid
      – Slimshadddyyy
      Jul 25 '14 at 4:11















    up vote
    0
    down vote













    Copy below file in your local



    /app/design/frontend/default/mytheme/template/catalog/product/view/type/options/configurable.phtml


    <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
    <option><?php echo $this->__('Choose an Option...') ?></option>
    </select>


    It shows 'Choose an Option...' as a default value



    You can change it like below to simply select the first real element in your select:



    $$('#attribute525 option')[1].selected = true;


    Check with your attributeid. The above is just an example.






    share|improve this answer























    • Thanks @Slimshadddyyy - Cant get this to work.. If I change the text from "Choose an Option..." to "Choose a Product..." Still the old msg Choose an Option comes up in the drop box.. I have refreshed cache & indexes.. Maybe a different file is actioning the function.. ? I added the '$$('#attribute525 option')[1].selected = true;' - still lookin at this
      – dan_code89
      Jul 24 '14 at 13:34










    • @dan_code89 on your product page, inspect the dropdown and check the attributeid of select. For me its attribute502. For you it could be something else. Pass that attributeid
      – Slimshadddyyy
      Jul 25 '14 at 4:11













    up vote
    0
    down vote










    up vote
    0
    down vote









    Copy below file in your local



    /app/design/frontend/default/mytheme/template/catalog/product/view/type/options/configurable.phtml


    <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
    <option><?php echo $this->__('Choose an Option...') ?></option>
    </select>


    It shows 'Choose an Option...' as a default value



    You can change it like below to simply select the first real element in your select:



    $$('#attribute525 option')[1].selected = true;


    Check with your attributeid. The above is just an example.






    share|improve this answer














    Copy below file in your local



    /app/design/frontend/default/mytheme/template/catalog/product/view/type/options/configurable.phtml


    <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
    <option><?php echo $this->__('Choose an Option...') ?></option>
    </select>


    It shows 'Choose an Option...' as a default value



    You can change it like below to simply select the first real element in your select:



    $$('#attribute525 option')[1].selected = true;


    Check with your attributeid. The above is just an example.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 24 '14 at 12:49

























    answered Jul 24 '14 at 12:38









    Slimshadddyyy

    3,13913180




    3,13913180












    • Thanks @Slimshadddyyy - Cant get this to work.. If I change the text from "Choose an Option..." to "Choose a Product..." Still the old msg Choose an Option comes up in the drop box.. I have refreshed cache & indexes.. Maybe a different file is actioning the function.. ? I added the '$$('#attribute525 option')[1].selected = true;' - still lookin at this
      – dan_code89
      Jul 24 '14 at 13:34










    • @dan_code89 on your product page, inspect the dropdown and check the attributeid of select. For me its attribute502. For you it could be something else. Pass that attributeid
      – Slimshadddyyy
      Jul 25 '14 at 4:11


















    • Thanks @Slimshadddyyy - Cant get this to work.. If I change the text from "Choose an Option..." to "Choose a Product..." Still the old msg Choose an Option comes up in the drop box.. I have refreshed cache & indexes.. Maybe a different file is actioning the function.. ? I added the '$$('#attribute525 option')[1].selected = true;' - still lookin at this
      – dan_code89
      Jul 24 '14 at 13:34










    • @dan_code89 on your product page, inspect the dropdown and check the attributeid of select. For me its attribute502. For you it could be something else. Pass that attributeid
      – Slimshadddyyy
      Jul 25 '14 at 4:11
















    Thanks @Slimshadddyyy - Cant get this to work.. If I change the text from "Choose an Option..." to "Choose a Product..." Still the old msg Choose an Option comes up in the drop box.. I have refreshed cache & indexes.. Maybe a different file is actioning the function.. ? I added the '$$('#attribute525 option')[1].selected = true;' - still lookin at this
    – dan_code89
    Jul 24 '14 at 13:34




    Thanks @Slimshadddyyy - Cant get this to work.. If I change the text from "Choose an Option..." to "Choose a Product..." Still the old msg Choose an Option comes up in the drop box.. I have refreshed cache & indexes.. Maybe a different file is actioning the function.. ? I added the '$$('#attribute525 option')[1].selected = true;' - still lookin at this
    – dan_code89
    Jul 24 '14 at 13:34












    @dan_code89 on your product page, inspect the dropdown and check the attributeid of select. For me its attribute502. For you it could be something else. Pass that attributeid
    – Slimshadddyyy
    Jul 25 '14 at 4:11




    @dan_code89 on your product page, inspect the dropdown and check the attributeid of select. For me its attribute502. For you it could be something else. Pass that attributeid
    – Slimshadddyyy
    Jul 25 '14 at 4:11












    up vote
    0
    down vote













    Navigate to Catalog->Attributes->Manage Attributes in your magento admin and search for your attribute.



    Click to edit and select No to Values required.



    Hope it will work.



    JQuery to default select first value is -



    jQuery('#attribute135>option:eq(1)').attr('selected', true);





    share|improve this answer























    • we need to select the first option as default selected and not to by pass validation
      – Slimshadddyyy
      Jul 24 '14 at 12:25












    • Alright, so you are having 3 attributes and you want to select first option as default selected for all 3 attributes ?
      – TBI
      Jul 24 '14 at 12:29










    • Thanks SlimShadddyyy - I tried that - I still get flagged for Required fields.
      – dan_code89
      Jul 24 '14 at 12:30










    • What if you just remove the Please Select message from Custom Option Dropdown on Magento Product View and making the first option as default selected ?
      – Slimshadddyyy
      Jul 24 '14 at 12:32












    • Yeah - If it can select the first attribute as default I would be very happy :) Or if I can turn off the validation (Required Fields) that would also be great - But I think configureable products are always Required..
      – dan_code89
      Jul 24 '14 at 12:32















    up vote
    0
    down vote













    Navigate to Catalog->Attributes->Manage Attributes in your magento admin and search for your attribute.



    Click to edit and select No to Values required.



    Hope it will work.



    JQuery to default select first value is -



    jQuery('#attribute135>option:eq(1)').attr('selected', true);





    share|improve this answer























    • we need to select the first option as default selected and not to by pass validation
      – Slimshadddyyy
      Jul 24 '14 at 12:25












    • Alright, so you are having 3 attributes and you want to select first option as default selected for all 3 attributes ?
      – TBI
      Jul 24 '14 at 12:29










    • Thanks SlimShadddyyy - I tried that - I still get flagged for Required fields.
      – dan_code89
      Jul 24 '14 at 12:30










    • What if you just remove the Please Select message from Custom Option Dropdown on Magento Product View and making the first option as default selected ?
      – Slimshadddyyy
      Jul 24 '14 at 12:32












    • Yeah - If it can select the first attribute as default I would be very happy :) Or if I can turn off the validation (Required Fields) that would also be great - But I think configureable products are always Required..
      – dan_code89
      Jul 24 '14 at 12:32













    up vote
    0
    down vote










    up vote
    0
    down vote









    Navigate to Catalog->Attributes->Manage Attributes in your magento admin and search for your attribute.



    Click to edit and select No to Values required.



    Hope it will work.



    JQuery to default select first value is -



    jQuery('#attribute135>option:eq(1)').attr('selected', true);





    share|improve this answer














    Navigate to Catalog->Attributes->Manage Attributes in your magento admin and search for your attribute.



    Click to edit and select No to Values required.



    Hope it will work.



    JQuery to default select first value is -



    jQuery('#attribute135>option:eq(1)').attr('selected', true);






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 24 '14 at 12:50

























    answered Jul 24 '14 at 12:22









    TBI

    2,2361617




    2,2361617












    • we need to select the first option as default selected and not to by pass validation
      – Slimshadddyyy
      Jul 24 '14 at 12:25












    • Alright, so you are having 3 attributes and you want to select first option as default selected for all 3 attributes ?
      – TBI
      Jul 24 '14 at 12:29










    • Thanks SlimShadddyyy - I tried that - I still get flagged for Required fields.
      – dan_code89
      Jul 24 '14 at 12:30










    • What if you just remove the Please Select message from Custom Option Dropdown on Magento Product View and making the first option as default selected ?
      – Slimshadddyyy
      Jul 24 '14 at 12:32












    • Yeah - If it can select the first attribute as default I would be very happy :) Or if I can turn off the validation (Required Fields) that would also be great - But I think configureable products are always Required..
      – dan_code89
      Jul 24 '14 at 12:32


















    • we need to select the first option as default selected and not to by pass validation
      – Slimshadddyyy
      Jul 24 '14 at 12:25












    • Alright, so you are having 3 attributes and you want to select first option as default selected for all 3 attributes ?
      – TBI
      Jul 24 '14 at 12:29










    • Thanks SlimShadddyyy - I tried that - I still get flagged for Required fields.
      – dan_code89
      Jul 24 '14 at 12:30










    • What if you just remove the Please Select message from Custom Option Dropdown on Magento Product View and making the first option as default selected ?
      – Slimshadddyyy
      Jul 24 '14 at 12:32












    • Yeah - If it can select the first attribute as default I would be very happy :) Or if I can turn off the validation (Required Fields) that would also be great - But I think configureable products are always Required..
      – dan_code89
      Jul 24 '14 at 12:32
















    we need to select the first option as default selected and not to by pass validation
    – Slimshadddyyy
    Jul 24 '14 at 12:25






    we need to select the first option as default selected and not to by pass validation
    – Slimshadddyyy
    Jul 24 '14 at 12:25














    Alright, so you are having 3 attributes and you want to select first option as default selected for all 3 attributes ?
    – TBI
    Jul 24 '14 at 12:29




    Alright, so you are having 3 attributes and you want to select first option as default selected for all 3 attributes ?
    – TBI
    Jul 24 '14 at 12:29












    Thanks SlimShadddyyy - I tried that - I still get flagged for Required fields.
    – dan_code89
    Jul 24 '14 at 12:30




    Thanks SlimShadddyyy - I tried that - I still get flagged for Required fields.
    – dan_code89
    Jul 24 '14 at 12:30












    What if you just remove the Please Select message from Custom Option Dropdown on Magento Product View and making the first option as default selected ?
    – Slimshadddyyy
    Jul 24 '14 at 12:32






    What if you just remove the Please Select message from Custom Option Dropdown on Magento Product View and making the first option as default selected ?
    – Slimshadddyyy
    Jul 24 '14 at 12:32














    Yeah - If it can select the first attribute as default I would be very happy :) Or if I can turn off the validation (Required Fields) that would also be great - But I think configureable products are always Required..
    – dan_code89
    Jul 24 '14 at 12:32




    Yeah - If it can select the first attribute as default I would be very happy :) Or if I can turn off the validation (Required Fields) that would also be great - But I think configureable products are always Required..
    – dan_code89
    Jul 24 '14 at 12:32










    up vote
    0
    down vote













    This could get tricky if you have 2+ options (it's confusing but what you describe above is 1 option with 3 selection), says Color and Size. Assuming Color is the first Option, Size's selection will be updated once Color is selected.



    For example, you have a shirt available in Red in size (S,L) and Blue in size (M,L), once you select Blue, Magento observe the event 'onChange' of the Color option and update the Size option to M, L.



    This is what I would do to get it done correctly in PrototypeJS:



    <script type='text/javascript>
    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);

    document.observe('dom:loaded', function() {
    var el = $('attribute<?php echo $_attribute->getAttributeId() ?>');
    el.selectedIndex = 1;
    el[0].remove();
    if ("createEvent" in document) {
    var ev = document.createEvent("HTMLEvents");
    ev.initEvent("change", false, true);
    el.dispatchEvent(ev);
    } else {
    el.fireEvent("onchange");
    }
    </script>


    in configurable.phtml, please note the fireEvent / dispatchEvent.
    el[0].remove will get rid of "Select an option.."



    This is the least intrusive method that I know of






    share|improve this answer























    • Have tried this @William Tran - sorry I couldnt get it working.. error msgs... Can you explain it a bit more & the fireEvent?. I am not a JavaScript writer.. Just HTML & CSS are my main thing.. Would be Much Obliged for a solution here :/
      – dan_code89
      Jul 24 '14 at 17:23












    • can you let me know what kind of error message?
      – William Tran
      Jul 24 '14 at 22:28










    • My answer is for configurable product with one option: you have to populate $_attribute before getting to the script.
      – William Tran
      Jul 25 '14 at 1:16

















    up vote
    0
    down vote













    This could get tricky if you have 2+ options (it's confusing but what you describe above is 1 option with 3 selection), says Color and Size. Assuming Color is the first Option, Size's selection will be updated once Color is selected.



    For example, you have a shirt available in Red in size (S,L) and Blue in size (M,L), once you select Blue, Magento observe the event 'onChange' of the Color option and update the Size option to M, L.



    This is what I would do to get it done correctly in PrototypeJS:



    <script type='text/javascript>
    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);

    document.observe('dom:loaded', function() {
    var el = $('attribute<?php echo $_attribute->getAttributeId() ?>');
    el.selectedIndex = 1;
    el[0].remove();
    if ("createEvent" in document) {
    var ev = document.createEvent("HTMLEvents");
    ev.initEvent("change", false, true);
    el.dispatchEvent(ev);
    } else {
    el.fireEvent("onchange");
    }
    </script>


    in configurable.phtml, please note the fireEvent / dispatchEvent.
    el[0].remove will get rid of "Select an option.."



    This is the least intrusive method that I know of






    share|improve this answer























    • Have tried this @William Tran - sorry I couldnt get it working.. error msgs... Can you explain it a bit more & the fireEvent?. I am not a JavaScript writer.. Just HTML & CSS are my main thing.. Would be Much Obliged for a solution here :/
      – dan_code89
      Jul 24 '14 at 17:23












    • can you let me know what kind of error message?
      – William Tran
      Jul 24 '14 at 22:28










    • My answer is for configurable product with one option: you have to populate $_attribute before getting to the script.
      – William Tran
      Jul 25 '14 at 1:16















    up vote
    0
    down vote










    up vote
    0
    down vote









    This could get tricky if you have 2+ options (it's confusing but what you describe above is 1 option with 3 selection), says Color and Size. Assuming Color is the first Option, Size's selection will be updated once Color is selected.



    For example, you have a shirt available in Red in size (S,L) and Blue in size (M,L), once you select Blue, Magento observe the event 'onChange' of the Color option and update the Size option to M, L.



    This is what I would do to get it done correctly in PrototypeJS:



    <script type='text/javascript>
    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);

    document.observe('dom:loaded', function() {
    var el = $('attribute<?php echo $_attribute->getAttributeId() ?>');
    el.selectedIndex = 1;
    el[0].remove();
    if ("createEvent" in document) {
    var ev = document.createEvent("HTMLEvents");
    ev.initEvent("change", false, true);
    el.dispatchEvent(ev);
    } else {
    el.fireEvent("onchange");
    }
    </script>


    in configurable.phtml, please note the fireEvent / dispatchEvent.
    el[0].remove will get rid of "Select an option.."



    This is the least intrusive method that I know of






    share|improve this answer














    This could get tricky if you have 2+ options (it's confusing but what you describe above is 1 option with 3 selection), says Color and Size. Assuming Color is the first Option, Size's selection will be updated once Color is selected.



    For example, you have a shirt available in Red in size (S,L) and Blue in size (M,L), once you select Blue, Magento observe the event 'onChange' of the Color option and update the Size option to M, L.



    This is what I would do to get it done correctly in PrototypeJS:



    <script type='text/javascript>
    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);

    document.observe('dom:loaded', function() {
    var el = $('attribute<?php echo $_attribute->getAttributeId() ?>');
    el.selectedIndex = 1;
    el[0].remove();
    if ("createEvent" in document) {
    var ev = document.createEvent("HTMLEvents");
    ev.initEvent("change", false, true);
    el.dispatchEvent(ev);
    } else {
    el.fireEvent("onchange");
    }
    </script>


    in configurable.phtml, please note the fireEvent / dispatchEvent.
    el[0].remove will get rid of "Select an option.."



    This is the least intrusive method that I know of







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 24 '14 at 14:20

























    answered Jul 24 '14 at 13:57









    William Tran

    64347




    64347












    • Have tried this @William Tran - sorry I couldnt get it working.. error msgs... Can you explain it a bit more & the fireEvent?. I am not a JavaScript writer.. Just HTML & CSS are my main thing.. Would be Much Obliged for a solution here :/
      – dan_code89
      Jul 24 '14 at 17:23












    • can you let me know what kind of error message?
      – William Tran
      Jul 24 '14 at 22:28










    • My answer is for configurable product with one option: you have to populate $_attribute before getting to the script.
      – William Tran
      Jul 25 '14 at 1:16




















    • Have tried this @William Tran - sorry I couldnt get it working.. error msgs... Can you explain it a bit more & the fireEvent?. I am not a JavaScript writer.. Just HTML & CSS are my main thing.. Would be Much Obliged for a solution here :/
      – dan_code89
      Jul 24 '14 at 17:23












    • can you let me know what kind of error message?
      – William Tran
      Jul 24 '14 at 22:28










    • My answer is for configurable product with one option: you have to populate $_attribute before getting to the script.
      – William Tran
      Jul 25 '14 at 1:16


















    Have tried this @William Tran - sorry I couldnt get it working.. error msgs... Can you explain it a bit more & the fireEvent?. I am not a JavaScript writer.. Just HTML & CSS are my main thing.. Would be Much Obliged for a solution here :/
    – dan_code89
    Jul 24 '14 at 17:23






    Have tried this @William Tran - sorry I couldnt get it working.. error msgs... Can you explain it a bit more & the fireEvent?. I am not a JavaScript writer.. Just HTML & CSS are my main thing.. Would be Much Obliged for a solution here :/
    – dan_code89
    Jul 24 '14 at 17:23














    can you let me know what kind of error message?
    – William Tran
    Jul 24 '14 at 22:28




    can you let me know what kind of error message?
    – William Tran
    Jul 24 '14 at 22:28












    My answer is for configurable product with one option: you have to populate $_attribute before getting to the script.
    – William Tran
    Jul 25 '14 at 1:16






    My answer is for configurable product with one option: you have to populate $_attribute before getting to the script.
    – William Tran
    Jul 25 '14 at 1:16












    up vote
    0
    down vote













    Open appdesignfrontend[your package][your theme]templatecatalogproductviewtypeoptionsconfigurable.phtml


    Now add the below java-script code after :-



    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);


    function fireEvent(element,event){

    if (document.createEventObject){

    // dispatch for IE

    var evt = document.createEventObject();

    return element.fireEvent('on'+event,evt)

    }

    else{

    // dispatch for firefox + others

    var evt = document.createEvent("HTMLEvents");

    evt.initEvent(event, true, true ); // event type,bubbling,cancelable

    return !element.dispatchEvent(evt);

    }

    }

    Event.observe(window, 'load', function() {

    spConfig.settings[0].selectedIndex = 1;

    obj = spConfig.settings[0]; // this grabs the first select item

    Event.observe(obj,'change',function(){});

    fireEvent(obj,'change'); // this simulates selecting the first option, which triggers

    spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
    });





    share|improve this answer



























      up vote
      0
      down vote













      Open appdesignfrontend[your package][your theme]templatecatalogproductviewtypeoptionsconfigurable.phtml


      Now add the below java-script code after :-



      var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);


      function fireEvent(element,event){

      if (document.createEventObject){

      // dispatch for IE

      var evt = document.createEventObject();

      return element.fireEvent('on'+event,evt)

      }

      else{

      // dispatch for firefox + others

      var evt = document.createEvent("HTMLEvents");

      evt.initEvent(event, true, true ); // event type,bubbling,cancelable

      return !element.dispatchEvent(evt);

      }

      }

      Event.observe(window, 'load', function() {

      spConfig.settings[0].selectedIndex = 1;

      obj = spConfig.settings[0]; // this grabs the first select item

      Event.observe(obj,'change',function(){});

      fireEvent(obj,'change'); // this simulates selecting the first option, which triggers

      spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
      });





      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        Open appdesignfrontend[your package][your theme]templatecatalogproductviewtypeoptionsconfigurable.phtml


        Now add the below java-script code after :-



        var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);


        function fireEvent(element,event){

        if (document.createEventObject){

        // dispatch for IE

        var evt = document.createEventObject();

        return element.fireEvent('on'+event,evt)

        }

        else{

        // dispatch for firefox + others

        var evt = document.createEvent("HTMLEvents");

        evt.initEvent(event, true, true ); // event type,bubbling,cancelable

        return !element.dispatchEvent(evt);

        }

        }

        Event.observe(window, 'load', function() {

        spConfig.settings[0].selectedIndex = 1;

        obj = spConfig.settings[0]; // this grabs the first select item

        Event.observe(obj,'change',function(){});

        fireEvent(obj,'change'); // this simulates selecting the first option, which triggers

        spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
        });





        share|improve this answer














        Open appdesignfrontend[your package][your theme]templatecatalogproductviewtypeoptionsconfigurable.phtml


        Now add the below java-script code after :-



        var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);


        function fireEvent(element,event){

        if (document.createEventObject){

        // dispatch for IE

        var evt = document.createEventObject();

        return element.fireEvent('on'+event,evt)

        }

        else{

        // dispatch for firefox + others

        var evt = document.createEvent("HTMLEvents");

        evt.initEvent(event, true, true ); // event type,bubbling,cancelable

        return !element.dispatchEvent(evt);

        }

        }

        Event.observe(window, 'load', function() {

        spConfig.settings[0].selectedIndex = 1;

        obj = spConfig.settings[0]; // this grabs the first select item

        Event.observe(obj,'change',function(){});

        fireEvent(obj,'change'); // this simulates selecting the first option, which triggers

        spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
        });






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 6 '16 at 14:46









        Caleb Kleveter

        6,98373767




        6,98373767










        answered Jan 6 '16 at 14:28









        Niraj Pathak

        12




        12






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24933460%2fset-default-value-on-configurable-drop-down-in-magento%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Lugert, Oklahoma