[Skip to main content](#vessel-content)

#   Dynamic Dropdowns with charateristics &amp; options

##

- **[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")**
- [![jschroeder's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13561-jschroeder "View jschroeder's Profile") Topic Author
- [ Offline](/forum/user/13561-jschroeder)

Less More

- Posts: 165
- Thank you received: 3
-
-

12 years 8 months ago -  12 years 8 months ago [\#144524](#144524) by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")  *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#144524 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")* was created by *[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")*

-- url of the page with the problem -- : [ 209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1](http://209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1)
-- HikaShop version -- : 2.3.0
-- Joomla version -- : 3.2.2
-- PHP version -- : x.x.x
-- Browser(s) name and version -- : XXXXX x.x.x
-- Error-message(debug-mod must be tuned on) -- : Error_message

I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.
Code:

select id="hikashop_product_characteristic_1" name="hikashop_product_characteristic[1]" class="inputbox" size="1" onchange="return hikashopUpdateVariant(this);"&gt; &lt;option value="2" selected="selected"&gt;Twin&lt;/option&gt; &lt;option value="6"&gt;Full&lt;/option&gt; &lt;option value="7"&gt;Queen&lt;/option&gt; &lt;option value="8"&gt;King&lt;/option&gt; &lt;option value="9"&gt;Cal King&lt;/option&gt; &lt;/select&gt; &lt;select id="hikashop_product_option_1" name="hikashop_product_option[1]" class="inputbox" size="1" onchange="hikashopChangeOption();"&gt; &lt;option value="0" selected="selected"&gt;No&lt;/option&gt; &lt;option value="775"&gt; Twin ( + $39.99 )&lt;/option&gt; &lt;option value="774"&gt; Twin Heavy Duty ( + $49.99 )&lt;/option&gt; &lt;option value="769"&gt; Twin Heavy Duty Glideamatic ( + $59.99 )&lt;/option&gt; &lt;option value="772"&gt; Twin XL ( + $39.99 )&lt;/option&gt; &lt;option value="771"&gt; Twin XL Heavy Duty ( + $49.99 )&lt;/option&gt; &lt;option value="770"&gt; Twin XL Heavy Duty Glideamatic ( + $59.99 )&lt;/option&gt; &lt;option value="776"&gt; Full ( + $39.99 )&lt;/option&gt; &lt;option value="777"&gt; Full Heavy Duty ( + $49.99 )&lt;/option&gt; &lt;option value="778"&gt; Full Heavy Duty Glideamatic ( + $59.99 )&lt;/option&gt; &lt;option value="773"&gt; Queen ( + $49.99 )&lt;/option&gt; &lt;option value="779"&gt; Queen Heavy Duty ( + $59.99 )&lt;/option&gt; &lt;option value="780"&gt; Queen Heavy Duty Glideamatic ( + $99.99 )&lt;/option&gt; &lt;option value="781"&gt; King ( + $59.99 )&lt;/option&gt; &lt;option value="782"&gt; King Heavy Duty ( + $69.99 )&lt;/option&gt; &lt;option value="783"&gt; King Heavy Duty Glideamatic ( + $99.99 )&lt;/option&gt; &lt;option value="784"&gt; Cal King ( + $59.99 )&lt;/option&gt; &lt;option value="785"&gt; Cal King Heavy Duty ( + $69.99 )&lt;/option&gt; &lt;option value="786"&gt; Cal King Heavy Duty Glideamatic ( + $99.99 )&lt;/option&gt; &lt;/select&gt;

The problem I am having is on inital page load: it is loading all the values under hikashop_product_option_1 and I only want it to show the value based off what the initial default value is in hikashop_product_characteristic_1
Here is my code on JS Fiddle
[ jsfiddle.net/HYQpj/4/](http://jsfiddle.net/HYQpj/4/)

I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?

Thanks,

Josh

Last edit: 12 years 8 months ago by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Eliot](/forum/user/1824-eliot "View Eliot's Profile")**
- [![Eliot's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar1824.png)](/forum/user/1824-eliot "View Eliot's Profile")
- [ Offline](/forum/user/1824-eliot)

Less More

- Posts: 2334
- Thank you received: 403
-
-

12 years 8 months ago [\#144570](#144570) by [Eliot](/forum/user/1824-eliot "View Eliot's Profile")  Replied by *[Eliot](/forum/user/1824-eliot "View Eliot's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#144570 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

Hi Josh,

I guess you should try to execute your js function at the page load.
You could put your code in a function, give it a name, and call it when the page load with the right option.
Something like this:
Code:

productcharacteristics.change(myDropdownFunction()); function myDropdownFunction() { var visibleOptions = subselectContains[this.options[this.selectedIndex].textContent]; if (visibleOptions.length != 0) { solutionOptions.hide(); solutionOptions.each(function () { for (var i = 0; i &lt;= visibleOptions.length; i++) { if (this.value == visibleOptions[i]) { $(this).show(); } } }); } else { solutionOptions.show(); } };

And edit the view to call this function. it's an idea.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")**
- [![jschroeder's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13561-jschroeder "View jschroeder's Profile") Topic Author
- [ Offline](/forum/user/13561-jschroeder)

Less More

- Posts: 165
- Thank you received: 3
-
-

12 years 8 months ago -  12 years 8 months ago [\#144632](#144632) by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")  Replied by *[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#144632 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

Hi, i updated your code in js fiddle with with the code you suggested below, but now the js does not work at all any ideas. All of the dropdowns show all the time. Also, maybe I am a little confused what would you put in the view file? are you talking about in my show_default.php file for the product page? Also, how would i go about calling the function. I am by no means a javascript expert.

Thanks,

Josh

Last edit: 12 years 8 months ago by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Eliot](/forum/user/1824-eliot "View Eliot's Profile")**
- [![Eliot's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar1824.png)](/forum/user/1824-eliot "View Eliot's Profile")
- [ Offline](/forum/user/1824-eliot)

Less More

- Posts: 2334
- Thank you received: 403
-
-

12 years 8 months ago [\#144640](#144640) by [Eliot](/forum/user/1824-eliot "View Eliot's Profile")  Replied by *[Eliot](/forum/user/1824-eliot "View Eliot's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#144640 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

Alright, then here is a way easier solution:

Just make every option like this one except the "Twin" ones.
Code:

&lt;option value="776" style="display:none;"&gt; Full ( + $39.99 )&lt;/option&gt;

Basically I just added style="display:none;" in the tag. it will hide it on load.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")**
- [![jschroeder's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13561-jschroeder "View jschroeder's Profile") Topic Author
- [ Offline](/forum/user/13561-jschroeder)

Less More

- Posts: 165
- Thank you received: 3
-
-

12 years 8 months ago -  12 years 8 months ago [\#144642](#144642) by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")  Replied by *[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#144642 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

Hi where would I go to add the display:none? These options are added on the fly in php so how would i add display=none? This is essentially what the javascript does that I sent you earlier only it will not work when the page loads.

Also, this solution would not work because there are times where there may be no twin mattresses and the default option is full, queen, or king instead so i see a javascript solution like i posted above being the only option.

Last edit: 12 years 8 months ago by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Eliot](/forum/user/1824-eliot "View Eliot's Profile")**
- [![Eliot's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar1824.png)](/forum/user/1824-eliot "View Eliot's Profile")
- [ Offline](/forum/user/1824-eliot)

Less More

- Posts: 2334
- Thank you received: 403
-
-

12 years 8 months ago [\#144731](#144731) by [Eliot](/forum/user/1824-eliot "View Eliot's Profile")  Replied by *[Eliot](/forum/user/1824-eliot "View Eliot's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#144731 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

My bad, i kind of forget that point.
So back to the first solution. What you can do is modify the view.html.php file of product to load your js.
It must be added in the form() function like this:
Code:

$js = 'yourcode'; $doc = JFactory::getDocument(); $doc-&gt;addScriptDeclaration($js);

And you can call the script in the view like this: Code:

&lt;script language="javascript" type="text/javascript"&gt;myDropdownFunction(nameOfTheFirstItem);&lt;/script&gt;

You can find the name of the first item in the php var $this-&gt;element-&gt;variants[0]-&gt;product_name.
So basically the code is loaded in the page thanks to the three lines I gave you and then you call it inside the view with the first variant. You might not need the first code I gave you but the second is definitely the one that will allow you to execute your JS on page load.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")**
- [![jschroeder's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13561-jschroeder "View jschroeder's Profile") Topic Author
- [ Offline](/forum/user/13561-jschroeder)

Less More

- Posts: 165
- Thank you received: 3
-
-

12 years 8 months ago -  12 years 8 months ago [\#144907](#144907) by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")  Replied by *[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#144907 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

Hi, this does not seem to work at all. I tried added this code below inside view.html.php and it does not seem to work I do not know if there is a snytax error or what in the code you gave me? All I get is a Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION Code:

productcharacteristics.change(myDropdownFunction()); function myDropdownFunction() { var visibleOptions = subselectContains[this.options[this.selectedIndex].textContent]; if (visibleOptions.length != 0) { solutionOptions.hide(); solutionOptions.each(function () { for (var i = 0; i &lt;= visibleOptions.length; i++) { if (this.value == visibleOptions[i]) { $(this).show(); } } }); } else { solutionOptions.show(); } };

Last edit: 12 years 8 months ago by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")**
- [![jschroeder's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13561-jschroeder "View jschroeder's Profile") Topic Author
- [ Offline](/forum/user/13561-jschroeder)

Less More

- Posts: 165
- Thank you received: 3
-
-

12 years 8 months ago -  12 years 8 months ago [\#144913](#144913) by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")  Replied by *[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#144913 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

I think I may have come up with another solution that my work as well. How can I add unique classes to each of the options under each dropdown characteristics for the options?? I have been looking inside of the options.php file but have not been able to get this to work.

Right now the charcteristics are &lt;option value="700"&gt;. But i would like it to be like this
&lt;option value ="700" class="option1"&gt;
&lt;option value ="701" class="option2"&gt;

I would like to use the word option along with the variants id as the "class" name for the option.

so I know it would be class="option $variant-&gt;product_id" but I have no idea how or where to implement this in the code.

I have been trying to figure this out for the longest time. It seems the javascript is much easier if i could just have individual classes for each option value.
Thanks,

Josh

Last edit: 12 years 8 months ago by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14278
-
-

12 years 8 months ago [\#145089](#145089) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#145089 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

You can add such class by changing the line: Code:

$this-&gt;values[] = JHTML::_('select.option', $variant-&gt;product_id,$text);

to: Code:

$this-&gt;values[] = JHTML::_('select.option', $variant-&gt;product_id,$text,array('attr'=&gt;'class="'.$variant-&gt;product_id.'"'));

in the file "option" of the view "product" via the menu Display&gt;Views.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")**
- [![jschroeder's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13561-jschroeder "View jschroeder's Profile") Topic Author
- [ Offline](/forum/user/13561-jschroeder)

Less More

- Posts: 165
- Thank you received: 3
-
-

12 years 8 months ago [\#145101](#145101) by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")  Replied by *[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#145101 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

Hi, Nicolas thanks for the response, but I could not get this to work i got the following error:

Fatal error: Cannot access empty property in /xxx/xxxxx/xxxxxxx/libraries/cms/html/select.php on line 477

How can I fix this??

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14278
-
-

12 years 8 months ago [\#145108](#145108) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#145108 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

try like that instead: Code:

$this-&gt;values[] = JHTML::_('select.option', $variant-&gt;product_id,$text,array('attr'=&gt;'class="'.$variant-&gt;product_id.'"','option.attr'=&gt;'attr'));

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")**
- [![jschroeder's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13561-jschroeder "View jschroeder's Profile") Topic Author
- [ Offline](/forum/user/13561-jschroeder)

Less More

- Posts: 165
- Thank you received: 3
-
-

12 years 8 months ago -  12 years 8 months ago [\#145116](#145116) by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")  Replied by *[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#145116 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

Hi, the error went away i changed the code like you suggested, but there is still no class showing up in the product options on the frontend

Last edit: 12 years 8 months ago by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14278
-
-

12 years 8 months ago [\#145230](#145230) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#145230 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

You apparently also need to change the line: Code:

$html = JHTML::_('select.genericlist', $this-&gt;values, $map, 'class="inputbox" size="1" onchange="hikashopChangeOption();"', 'value', 'text', (int)$value,$id );

to: Code:

$html = JHTML::_('select.genericlist', $this-&gt;values, $map, array('attr'=&gt;'class="'.$variant-&gt;product_id.'"','option.attr'=&gt;'attr','list.attr'=&gt;'class="inputbox" size="1" onchange="hikashopChangeOption();"','option.key'=&gt;'value','option.text'=&gt;'text','list.select'=&gt;(int)$value,'id'=&gt;$id));

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")**
- [![jschroeder's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13561-jschroeder "View jschroeder's Profile") Topic Author
- [ Offline](/forum/user/13561-jschroeder)

Less More

- Posts: 165
- Thank you received: 3
-
-

12 years 8 months ago [\#145285](#145285) by [jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")  Replied by *[jschroeder](/forum/user/13561-jschroeder "View jschroeder's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#145285 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

Thank you so much that worked! How would I go about doing the same thing for the characteristics options as well? I cannot seem to find the php file that contains the select code for this.

Josh

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14278
-
-

12 years 8 months ago [\#145301](#145301) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Dynamic Dropdowns with charateristics &amp; options](/forum/31-development/865977-dynamic-dropdowns-with-charateristics-options#145301 "-- url of the page with the problem -- :   209.59.173.183/mattresses/1-sleep-pedic-hotel-firm.html?popup=1  -- HikaShop version -- : 2.3.0 -- Joomla version -- : 3.2.2 -- PHP version -- : x.x.x -- Browser(s) name and version -- : XXXXX x.x.x -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  I am trying to create a dynamic dropdown with my product options and characteristics dropdown. Here are both of my dropdowns below.  The problem I am having is on inital page load: it is loading all the values under hikashop&#95;product&#95;option&#95;1 and I only want it to show the value based off what the initial default value is in hikashop&#95;product&#95;characteristic&#95;1 Here is my code on JS Fiddle   jsfiddle.net/HYQpj/4/  I have tried for over 10 Hours today and have been unsuccessful at this. What can I do to get this to work?  Thanks,  Josh")*

A similar modification would have to be done in the file administrator/components/com_hikashop/types/characteristic.php

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg2NTk3Ny1keW5hbWljLWRyb3Bkb3ducy13aXRoLWNoYXJhdGVyaXN0aWNzLW9wdGlvbnM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.114 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)

[](#top)
