Note that there are some explanatory texts on larger screens.

plurals
  1. POonChange replace img src with dropdown title not value
    primarykey
    data
    text
    <p>I have a set of radio buttons that work when clicked where it will change the image based on the click. </p> <p>Now I want to change an image based on the dropdown box selection. Here is part of my script. Is using "title" not proper? </p> <p>**Also, it doesn't feel right that I have a function within a function... I'm just trying to figure out if I even need the <code>.change(function () {</code> part if it's already being triggered by the <code>select's onchange</code>? I tried with and without and it's still not replacing the image.</p> <pre><code>&lt;script type="text/javascript"&gt; function doCalc(){ var roomX = $('#room_str').val(); var otherroomX = $('#other_room').val(); var qtyX = $('#qty_str').val(); // etc. etc.. // below is code that pertains to what i'm trying to do var imgFldr2 = '/wp-content/uploads/2012/07/'; var imagename = $('#laserlite_color option:selected').attr('title'); $('#valance-colors-placeholder img').attr('src', imgFldr2 + imagename); }); // more code </code></pre> <p>and the dropdown box...</p> <pre><code>&lt;select name="laserlite_color" id="laserlite_color" onchange="doCalc();"&gt; &lt;option value="Gold 301" title="Gold-301.jpg"&gt;Gold&lt;/option&gt; &lt;option value="Chrome 303" title="Chrome-301.jpg"&gt;Chrome&lt;/option&gt; &lt;option value="Light Oak 304" title="Light-Oak-304.jpg"&gt;Light Oak&lt;/option&gt; &lt;option value="Dark Walnut 302" title="Dark-Walnut-302.jpg"&gt;Dark Walnut&lt;/option&gt; &lt;option value="White 307" title="White-307.jpg"&gt;White&lt;/option&gt; &lt;option value="Silk 630" title="Silk-630.jpg"&gt;Silk&lt;/option&gt; &lt;option value="Lilac 688" title="Lilac-688.jpg"&gt;Lilac&lt;/option&gt; &lt;option value="Blush 672" title="Blush-672.jpg"&gt;Blush&lt;/option&gt; &lt;option value="Sage 655" title="Sage-655.jpg"&gt;Sage&lt;/option&gt; &lt;option value="Denim 641" title="Denim-641.jpg"&gt;Denim&lt;/option&gt; &lt;option value="Black Satin 684" title="Black-Satin-684.jpg"&gt;Black Satin&lt;/option&gt; &lt;/select&gt;&lt;br&gt; &lt;div id="valance-colors-placeholder"&gt;&lt;img src="/wp-content/uploads/2012/07/Gold-301.jpg"&gt;&lt;/div&gt; </code></pre> <p>EDIT: I've updated my code with part of Nick's code below. I just want to explain that on this website I remember programmer's saying to use <code>alert('whatever variable you need to see returned here');</code> and that helps with seeing what part of your code is and isn't working properly. Thanks!!!</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