How to get Option 1 variant value within the Option 2 loop

MelonCiroc
New Member
4 0 0

Hello, 
I'm trying to get the Option 1 variant value on the product page, and depending on what is selected, I would like to render a specific header for Option 2.  

MelonCiroc_0-1608282101952.png

 

I would ideally like to do this without deeplinking.  Is there a way to set an outer variable, or use javascript/jquery to get the "is-selected" element?  

0 Likes
r8r
Shopify Expert
1437 157 478

You'll probably have to go through JS here. I usually like to render all elements that might be displayed at any point and hide them upon page load. Depending on what option is selected, I then do the show/hide toggling through JS. Makes sense?

Mario

Mario Rader [he] ★ If you want to achieve greatness, stop asking for permission. ★ Studio Mitte
• Meine Antwort war hilfreich? Hinterlass bitte ein Like.
• Meine Antwort hat Dein Problem behoben? Bitte akzeptiere sie als Lösung.
• Ich hab dir etwas erspart? Ich freue ich mich immer über eine kleine Aufmerksamkeit
• Ja, ich biete Shopify-Services & -Entwicklung und freue mich von Dir zu hören!
• Bitte teile einen Link zu der Seite, deren Problem Du in deinem Beitrag beschreibst!

• Yes, I provide Shopify-services & -development. Feel free to get in touch!
• Please share a link to the site, which you refer to in your problem description. This incredibly increases the chances of you receiving a useful answer!
• My answer was useful? Please leave a Like.
• My answer solved your issue? Please accept it as the solution.
• I saved you time or money? I'm always happy to receive a little thank you.
0 Likes
MelonCiroc
New Member
4 0 0

Hey appreciate the reply, I'm still a little confused and completely new to liquid.  In what file do I put the javascript?  The toggling makes perfect sense but still stumped on how to get the value of the Option 1 selection.

To clarify, I have 2 options, Option 1 can be "iphone" or "iphone charger".  If Option 1 is "iphone",  I want Option 2 to be labeled something, if Option 1 is "charger" then i want option 2 to be labeled something else.  How do I know/get what the value of Option1 is?

0 Likes
r8r
Shopify Expert
1437 157 478

Hi @MelonCiroc 

how do you define the labels for option2? Wouldn’t they need to be defined in the context of option1 as they depend on it? How many different ones are there?

if you’re not a programmer yourself, it’s gonna be hard explaining this to the point where you can build it. I can build that, but I’d need access to the code and depending on the existing code it might exceed what I can offer here pro bono.

Mario

Mario Rader [he] ★ If you want to achieve greatness, stop asking for permission. ★ Studio Mitte
• Meine Antwort war hilfreich? Hinterlass bitte ein Like.
• Meine Antwort hat Dein Problem behoben? Bitte akzeptiere sie als Lösung.
• Ich hab dir etwas erspart? Ich freue ich mich immer über eine kleine Aufmerksamkeit
• Ja, ich biete Shopify-Services & -Entwicklung und freue mich von Dir zu hören!
• Bitte teile einen Link zu der Seite, deren Problem Du in deinem Beitrag beschreibst!

• Yes, I provide Shopify-services & -development. Feel free to get in touch!
• Please share a link to the site, which you refer to in your problem description. This incredibly increases the chances of you receiving a useful answer!
• My answer was useful? Please leave a Like.
• My answer solved your issue? Please accept it as the solution.
• I saved you time or money? I'm always happy to receive a little thank you.
0 Likes