- Posts: 165
- Thank you received: 3
Dynamic Dropdowns with charateristics & options
- jschroeder
-
Topic Author
- Offline
-- 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.
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/
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
Please Log in or Create an account to join the conversation.
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:
And edit the view to call this function. it's an idea.
Please Log in or Create an account to join the conversation.
- jschroeder
-
Topic Author
- Offline
- Posts: 165
- Thank you received: 3
Thanks,
Josh
Please Log in or Create an account to join the conversation.
Just make every option like this one except the "Twin" ones.
Basically I just added style="display:none;" in the tag. it will hide it on load.
Please Log in or Create an account to join the conversation.
- jschroeder
-
Topic Author
- Offline
- Posts: 165
- Thank you received: 3
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.
Please Log in or Create an account to join the conversation.
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:
And you can call the script in the view like this:
You can find the name of the first item in the php var $this->element->variants[0]->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 or Create an account to join the conversation.
- jschroeder
-
Topic Author
- Offline
- Posts: 165
- Thank you received: 3
Please Log in or Create an account to join the conversation.
- jschroeder
-
Topic Author
- Offline
- Posts: 165
- Thank you received: 3
Right now the charcteristics are <option value="700">. But i would like it to be like this
<option value ="700" class="option1">
<option value ="701" class="option2">
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->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
Please Log in or Create an account to join the conversation.
to:
Please Log in or Create an account to join the conversation.
- jschroeder
-
Topic Author
- Offline
- Posts: 165
- Thank you received: 3
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 or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
- jschroeder
-
Topic Author
- Offline
- Posts: 165
- Thank you received: 3
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
- jschroeder
-
Topic Author
- Offline
- Posts: 165
- Thank you received: 3
Josh
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.