javascript - how to substract options two related selects html -
if have 3 units available , 2 selects hhtml select quantity, how can when client select 1 unit (option value=1) example in first select, option substract in second select, , show remaining units? ie, second select show 1 unit (option value=1) , 2 units (option value=2).i dont need show , hide. need if client select 1 unit in first select, in second can select 2 more. options value refers quantity
<select class="quantity" name="double room"> <option value="1">1</option> <option value="2">2</option <option value="3">3</option </select> <p> <select class="quantity" name="double room"> <option value="1">1</option> <option value="2">2</option <option value="3">3</option </select>
here quick solution, point in right direction. doesn't fancy preserve order, removes , returns options on second select.
https://jsfiddle.net/jpbjd40s/2/
// intialize value option missing #two var previousvalue = 1; // stuff on change. $('#one').on('change', function() { // put unselected option #one in #two. $('#two').append('<option value="' + previousvalue + '">' + previousvalue + '</option>'); // remember had. previousvalue = $('#one').val(); // remove option #two selected in #one. $('#two').children('[value="' + $('#one').val() + '"]').remove(); });
Comments
Post a Comment