2

I have 2 select attributes in frontend phone model and phone brand. I want these two attributes to be dependant i.e. If suppose I click on "Apple" all the phone models under "Apple" brand category should come in the second select option. All the data comes from backend. Any suggestions?

1
  • Did you give a go at JavaScript? Commented May 28, 2014 at 8:34

1 Answer 1

2

Have a look into the SelectUpdater JavaScript that is defined in js/mage/adminhtml/form.js

I know this is only in the admin section but you should be able to take this and make it work in the front end.

Basically what you need is a snippet of code linking the two selects together and the mappings between the two select's values.

<script type="text/javascript">
    var updater = new SelectUpdater(
        "select1", // id of first select
        "select2", // id of second select
        "none", // defaults
        "none", // defaults
        <?php echo $this->helper('some_helper')->getConfigInJsonFormat() ?>, // values in json format
        false
    );
    updater.update();
</script>

The values are returned in json format should be built from a helper and replaced into the html string just before being returned. The easiest way to build the values is to create an array of the following format.

array(
    'first_select_value1' => array(
        'second_select_value1' => 'second_select_text1',
        'second_select_value2' => 'second_select_text2',
    ),
    'first_select_value2' => array(
        'second_select_value3' => 'second_select_text3',
        'second_select_value4' => 'second_select_text4',
    )
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.