Note that there are some explanatory texts on larger screens.

plurals
  1. POHide/Show Accordion based on javascript functions
    primarykey
    data
    text
    <p>I have an accordion with one panel I would like to only show if certain criteria are met. The panel id is "product-options". </p> <p>I have a couple javascript functions, one is to verify states from a dropdown (dropdown id="province") and the other is to verify age with a checkbox (checkbox id="age_verification"). The accordion panel "product-options" is activated with a header, id="BuyThis". </p> <p>What I would like is to only show the panel "product-options" when the states match the list. </p> <p>Here is my script as is: </p> <pre><code>&lt;script&gt; // Validates State is in list of allowed for wine shipping... function validateState() { // Confirms province is allowed for wine shipping var states = ["Alaska", "Arizona", "California", "Colorado", ""]; if ($.inArray($("#province").val(), states) &lt;0) { alert("Shipping gifts containing alcohol to this state is prohibited by law. Please choose another item."); return false; } alert("Item Available! Please choose your options."); return true; } // Validates age verification is checked... function validateAge() { if (!$('#age_verification').is(':checked')) { alert("Please verify you are 21 years of age or older."); return false; } return true; } &lt;/script&gt; </code></pre> <p>Corresponding HTML:</p> <pre><code>&lt;h3 id="BuyThis" onclick="return validateState();"&gt;&lt;button class="Button buyThisBtn"&gt;&lt;i class="icon-shopping-cart"&gt;&lt;/i&gt;&amp;nbsp;&amp;nbsp;Buy This!&lt;/button&gt;&lt;/h3&gt; &lt;div class="ProductContainer" id="product-options"&gt; &lt;form&gt; [BODY OF ACCORDION PANEL WITH A BUNCH OF IRRELEVANT CODE......] &lt;button id="addtocart" type="submit" class="Button" onclick="validateAge(); return validateState();"&gt;&lt;i class="icon-shopping-cart"&gt;&lt;/i&gt; ADD TO CART&lt;/button&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>I tried incorporating the following to no avail: </p> <pre><code>$(function () { $("#buyThis").change(function () { if ($.inArray($("#province").val(), states) &lt;0) { alert("Shipping gifts containing alcohol to this state is prohibited by law. Please choose another item."); $("product-options").hide(); } $("product-options").show(); } </code></pre>
    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.
 

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