Note that there are some explanatory texts on larger screens.

plurals
  1. POMake it 100% of all
    primarykey
    data
    text
    <p>I have 3 dropdown boxes, in which there are values of 10 to 100. I want user to select cumulative value of 100 from all dropdown boxes. Which means, if I select 20 from the first dropdown box the next 2 dropdown should be left with the options of selecting total of 100</p> <p>What I have done so far is here: <a href="http://jsfiddle.net/rzBej/26/" rel="nofollow">CHECK IT HERE (JS FIDDLE)</a></p> <p><strong>HTML</strong> </p> <pre><code>&lt;select id="foreign" class="me"&gt; &lt;option value=""&gt;Foreign Policy&lt;/option&gt; &lt;option value="10"&gt;10%&lt;/option&gt; &lt;option value="20"&gt;20%&lt;/option&gt; &lt;option value="30"&gt;30%&lt;/option&gt; &lt;option value="40"&gt;40%&lt;/option&gt; &lt;option value="50"&gt;50%&lt;/option&gt; &lt;option value="60"&gt;60%&lt;/option&gt; &lt;option value="70"&gt;70%&lt;/option&gt; &lt;option value="80"&gt;80%&lt;/option&gt; &lt;option value="90"&gt;90%&lt;/option&gt; &lt;option value="100"&gt;100%&lt;/option&gt; &lt;/select&gt; &lt;select id="economy" class="me"&gt; &lt;option value=""&gt;Economy Policy&lt;/option&gt; &lt;option value="10"&gt;10%&lt;/option&gt; &lt;option value="20"&gt;20%&lt;/option&gt; &lt;option value="30"&gt;30%&lt;/option&gt; &lt;option value="40"&gt;40%&lt;/option&gt; &lt;option value="50"&gt;50%&lt;/option&gt; &lt;option value="60"&gt;60%&lt;/option&gt; &lt;option value="70"&gt;70%&lt;/option&gt; &lt;option value="80"&gt;80%&lt;/option&gt; &lt;option value="90"&gt;90%&lt;/option&gt; &lt;option value="100"&gt;100%&lt;/option&gt; &lt;/select&gt; &lt;select id="social" class="me"&gt; &lt;option value=""&gt;Social Policy&lt;/option&gt; &lt;option value="10"&gt;10%&lt;/option&gt; &lt;option value="20"&gt;20%&lt;/option&gt; &lt;option value="30"&gt;30%&lt;/option&gt; &lt;option value="40"&gt;40%&lt;/option&gt; &lt;option value="50"&gt;50%&lt;/option&gt; &lt;option value="60"&gt;60%&lt;/option&gt; &lt;option value="70"&gt;70%&lt;/option&gt; &lt;option value="80"&gt;80%&lt;/option&gt; &lt;option value="90"&gt;90%&lt;/option&gt; &lt;option value="100"&gt;100%&lt;/option&gt; &lt;/select&gt; &lt;br /&gt; &lt;span id="message"&gt;&lt;/span&gt; </code></pre> <p><strong>JavaScript</strong> </p> <pre><code>/*var total = new Array(); $('#foreign option').each(function() { total.push($(this).val()); }); console.log(total);*/ var total = 100; var ids = ['foreign', 'social', 'economy']; var current_selected; $('.me').change(function() { current_selected = $(this).attr('id'); var socval = $('#' + current_selected + ' option:selected').val(); total = total - socval; if ($.inArray($(this).attr('id'), ids) &gt; -1) { ids.splice($.inArray($(this).attr('id'), ids), 1); } for (var i = 0; i &lt; ids.length; i++) { $('#' + ids[i] + ' option').each(function() { if ($(this).val() &gt;= total) { $(this).attr('disabled', true); } else { $(this).attr('disabled', false); } }); } if (total &lt;= 0) { total = 100; } console.log(total); ids.push(current_selected); }); </code></pre> <p>It is pretty much working, with some minor faults.</p> <p><strong>UPDATE</strong> I think I solved it. </p> <p><a href="http://jsfiddle.net/rzBej/61/" rel="nofollow">SOLVED FIDDLE</a></p> <p>Thanks who helped. </p> <p>Regards</p>
    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.
    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