Note that there are some explanatory texts on larger screens.

plurals
  1. POPopulate jquery select drop down form with multiple lists
    primarykey
    data
    text
    <p>I've seen so many different posts that pertain to my situation, but I'm still learning server side and js code, so I just don't understand how to apply it to my problem yet. </p> <p>I'm trying to build an order form to choose shirts/apparel to get screen printed. I don't have all the code in the form yet, as I'm already having problems, but here is the basic markup: (Keep in mind I plan on having a monetary value on the final selection to put towards a price estimate calculator with other sections in the form after I figure this part out.)</p> <p>I don't know how to populate the third and fourth drop down, and I can already tell with my jquery markup, that <code>if($(this).val() == "100% Polyester/100% Cotton")</code> etc. will start to repeat itself.</p> <p>HTML:</p> <pre><code> ` &lt;form&gt; &lt;select name="garment"&gt; &lt;option selected&gt;Choose An Option&lt;/option&gt; &lt;option&gt;Short Sleeve T-Shirts&lt;/option&gt; &lt;option&gt;Hoodies/Sweatshirts&lt;/option&gt; &lt;option&gt;Long Sleeve T-Shirts&lt;/option&gt; &lt;option&gt;Tank Tops&lt;/option&gt; &lt;option&gt;Shorts &amp;amp; Pants&lt;/option&gt; &lt;option&gt;Hats &amp;amp; Accessories&lt;/option&gt; &lt;/select&gt; &lt;select name="type"&gt; &lt;option selected disabled&gt;Choose an Option&lt;/option&gt; &lt;/select&gt; &lt;select name="style"&gt; &lt;option selected disabled&gt;Choose an Option&lt;/option&gt; &lt;/select&gt; &lt;select name="color"&gt; &lt;option selected disabled&gt;Choose a Color&lt;/option&gt; &lt;/select&gt; &lt;/form&gt;` </code></pre> <p>jquery:</p> <pre><code> `$(document).ready(function() { $garment = $("select[name='garment']"); $type = $("select[name='type']"); $style = $("select[name='style']"); $garment.change(function() { if($(this).val() == "Short Sleeve T-Shirts") { $("select[name='type'] option").remove(); $("&lt;option&gt;100% Cotton&lt;/option&gt;").appendTo($type); $("&lt;option&gt;Blended&lt;/option&gt;").appendTo($type); $("&lt;option&gt;100% Polyester/Athletic&lt;/option&gt;").appendTo($type); } if($(this).val() == "100% Cotton") { $("select[name='style'] option").remove(); $("&lt;option&gt;Regular Fit&lt;/option&gt;").appendTo($style); $("&lt;option&gt;Premium Slim/Fashion Fit&lt;/option&gt;").appendTo($style); $("&lt;option&gt;Women's Cut&lt;/option&gt;").appendTo($style); } if($(this).val() == "Blended") { $("select[name='style'] option").remove(); $("&lt;option&gt;Regular Fit&lt;/option&gt;").appendTo($style); $("&lt;option&gt;Premium Slim/Fashion Fit&lt;/option&gt;").appendTo($style); $("&lt;option&gt;Women's Cut&lt;/option&gt;").appendTo($style); } if($(this).val() == "100% Polyester/Athletic") { $("select[name='style'] option").remove(); $("&lt;option&gt;Men's&lt;/option&gt;").appendTo($style); $("&lt;option&gt;Women's&lt;/option&gt;").appendTo($style); } }); });` </code></pre>
    singulars
    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.
 

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