Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery - do something when not select an option
    primarykey
    data
    text
    <p>My question is similar to this : <a href="https://stackoverflow.com/questions/7309730/jquery-select-option-disabled-if-selected-in-multiple-select-boxes">jQuery &lt;select&gt; option disabled if selected in multiple &lt;select&gt; boxes</a></p> <p>and this : <a href="https://stackoverflow.com/questions/4610652/jquery-select-option-disabled-if-selected-in-other-select">jQuery &lt;select&gt; option disabled if selected in other &lt;select&gt;</a></p> <p>but different.</p> <p>I have this html form:</p> <pre><code>&lt;form method="post" action="" name="form_letter"&gt; &lt;label for="letter"&gt;Letter&lt;/label&gt;&lt;br&gt; &lt;select multiple="multiple" name="letter[]" id="letter"&gt; &lt;option value="A"&gt;A&lt;/option&gt; &lt;option value="B"&gt;B&lt;/option&gt; &lt;option value="C"&gt;C&lt;/option&gt; &lt;/select&gt; &lt;label for="list_of_a"&gt;List of A&lt;/label&gt;&lt;br&gt; &lt;select multiple="multiple" name="list_of_a[]" id="list_of_a"&gt; &lt;option value="A1"&gt;A1&lt;/option&gt; &lt;option value="A2"&gt;A2&lt;/option&gt; &lt;option value="A3"&gt;A3&lt;/option&gt; &lt;option value="A4"&gt;A4&lt;/option&gt; &lt;/select&gt; &lt;label for="list_of_b"&gt;List of B&lt;/label&gt;&lt;br&gt; &lt;select multiple="multiple" name="list_of_b[]" id="list_of_b"&gt; &lt;option value="B1"&gt;B1&lt;/option&gt; &lt;option value="B2"&gt;B2&lt;/option&gt; &lt;option value="B3"&gt;B3&lt;/option&gt; &lt;option value="B4"&gt;B4&lt;/option&gt; &lt;/select&gt; &lt;label for="list_of_c"&gt;List of C&lt;/label&gt;&lt;br&gt; &lt;select multiple="multiple" name="list_of_c[]" id="list_of_c"&gt; &lt;option value="C1"&gt;C1&lt;/option&gt; &lt;option value="C2"&gt;C2&lt;/option&gt; &lt;option value="C3"&gt;C3&lt;/option&gt; &lt;option value="C4"&gt;C4&lt;/option&gt; &lt;/select&gt; &lt;input type="submit" value="Save"&gt; &lt;/form&gt;​ </code></pre> <p>what i want to achieve is when an <code>option</code> of <code>select[name="letter[]"]</code> is not selected and then click the <code>submit</code> button, the <code>select</code> list of corresponding letter is <code>null</code> or <code>empty</code>.</p> <p>the scenarios:<br> 1. If <code>option</code> A of <code>select[name="letter[]"]</code> is not selected, then click the <code>submit</code> button, the <code>select[name="list_of_a[]"]</code> will be <code>empty</code> or <code>null</code> even if one of its options selected.<br><br> 2. The same thing goes for B and C.<br><br> 3. If none of the <code>letter</code>'s options selected, then <code>list_of_a</code>, <code>list_of_b</code>, and <code>list_of_c</code> are empty.<br></p> <p>this is my js :</p> <pre><code>$("form[name='form_letter']").on("submit", function(e) { if ($("select[name='letter[]']").find("option:not(:selected)").val() == "A") { $("select[name='list_of_a[]']").val(""); }; if ($("select[name='letter[]']").find("option:not(:selected)").val() == "B") { $("select[name='list_of_b[]']").val(""); }; if ($("select[name='letter[]']").find("option:not(:selected)").val() == "C") { $("select[name='list_of_c[]']").val(""); }; alert("A = " + $("select[name='list_of_a[]']").val() + " and B = " + $("select[name='list_of_b[]']").val() + " and C = " + $("select[name='list_of_c[]']").val()); e.preventDefault(); return false; });​ </code></pre> <p>I have been working on it here <a href="http://jsfiddle.net/VPhPv/21/" rel="nofollow noreferrer">http://jsfiddle.net/VPhPv/21/</a> <br> but got stuck. help me please.</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.
 

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