Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript item selector
    primarykey
    data
    text
    <p>I'm trying to create a kind of item selector using JavaScript. The selector would be similar to the setup below:</p> <pre><code>&lt;label&gt;Stone&lt;/label&gt; &lt;select id="stone"&gt; &lt;option value="aquamarine"&gt;Aquamarine&lt;/option&gt; &lt;option value="pink-topaz"&gt;Pink Topaz&lt;/option&gt; &lt;option value="tourmaline"&gt;Tourmaline&lt;/option&gt; &lt;/select&gt; &lt;label&gt;Metal&lt;/label&gt; &lt;select id="metal"&gt; &lt;option value="silver"&gt;Silver&lt;/option&gt; &lt;option value="platinum"&gt;Platinum&lt;/option&gt; &lt;option value="white-gold"&gt;White Gold&lt;/option&gt; &lt;option value="yellow-gold"&gt;Yellow Gold&lt;/option&gt; &lt;option value="rose-gold"&gt;Rose Gold&lt;/option&gt; &lt;/select&gt; </code></pre> <p>With an image container like so:</p> <pre><code>&lt;img src="path/to/image/silver_aquamarine.jpg" id="imageToSwap"&gt; </code></pre> <p>And the JavaScript as follows:</p> <pre><code>$('#stone, #metal').on('change', function() { $('#imageToSwap').prop('src', ['path/to/image/', $('#metal').val(), '_', $('#stone').val(), '.jpg'].join('') ); }); </code></pre> <p>And all that is working just fine. What I'm wondering is (and apologies in advance for having NO idea how to approach this) is there a way pull in other values that are associated with the image. For example, can I bring in the price associated with that selection? </p> <p>Or, should I be approaching this in an entirely different way? Maybe an array of items, each with an image, price, stone and metal, that are shown based on the selection but using something similar to a filter?</p> <p>Also, I'll need to create a fallback for what happens if the option doesn't exist. Let's say all combinations exist except for Aquamarine + Rose Gold. How could I add a message saying "option doesn't exist"?</p> <p>Any help here would be hugely appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload