Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery - content to appear on ONE particular select option.
    primarykey
    data
    text
    <p>I am new here. I am trying to learn jquery - and i have a problem that I can't fix. I think I am pretty close? but i've worked myself up into a muddle over it and now i cant see the wood for the trees.</p> <p>I have a form with a select in it. if the user selects the option 'YES' then i want another peice of content to appear. if the user selects no, then they just carry on filling in the form. i do realise that perhaps this could have been done with radio buttons, but i am bound to the snippet of html i have and can't change it. </p> <pre><code>&lt;form&gt; &lt;select id="test-select"&gt; &lt;option&gt;select&lt;/option&gt; &lt;option&gt;yes&lt;/option&gt; &lt;option&gt;no&lt;/option&gt; &lt;/select&gt; &lt;div class="show-me"&gt; &lt;p&gt;HOORAAAAYYYYYYYYYY!!!!!!!&lt;/p&gt; &lt;/div&gt; &lt;!--more form goes below this line here - not important to the question --&gt; &lt;/form&gt; </code></pre> <p>so far, i have the jquery working that it can get the values of the options. but then i am stuck. in my head i realise i need to do something IF the value of the option equals YES but i have no idea how to write that. the piece below is not working at all for me.</p> <pre><code>$(function(){ $("#test-select").change(function(){ var selectedValue = $(this).find(":selected").val(); console.log("the value you selected: " + selectedValue); if $(selectedValue).contains('yes') { console.log("you have selected yes - so write something to show the div now"); } else { console.log("you have not selected yes, carry on filling in form"); } }); }); </code></pre> <p>can anyone explain the next step to me please, so i can understand jquery better and where i am slipping up</p> <p>i have seen a post here where someone has content changing on each different select, but i only want my div to appear when YES has been selected so i couldn't translate that into how to fix my problem unfortuantely. i did try!</p> <p>thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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