i have two select box, now what i want is i want to move option from one select box to another via a button
below is my code:
php
<table>
<tr>
<td>
<select size="5" id="suppliedMovies" name="suppliedMovies">
<option selected="selected" value="">Select Movie</option>
<option value="1">sholay</option>
<option value="3">Jism</option>
<option value="4">Rog</option>
<option value="5">Zeher</option>
<option value="6">Awarpan</option>
<option value="7">Paap</option>
<option value="8">paanch<option>
<option value="9">no entry</option>
</select>
</td>
<td>
<input type="button" id="toRight" value=">>"><br>
<input type="button" id="toLeft" value="<<">
</td>
<td>
<select size="5" id="accquiredMovies" name="accquiredMovies">
<option> No item right now</option>
</select>
</td>
</tr>
</table>
Jquery
jQuery(document).ready( function() {
function displayVals() {
var myValues = jQuery("#suppliedMovies").val();
return myValues;
}
jQuery('#toRight').click(function(){
var x=displayVals();
console.log(x);
var txt=jQuery("#suppliedMovies option[value='"+x+"']").text();
console.log(txt);
if(x!=''){
jQuery('#accquiredMovies').append("<option value='"+x+"' >"+txt+"</option>");
}
});
});
i m using above jQuery, that is working fine but, i want that
when one item is copy from one select box to another select box, then that item should be disable(or probably delete) from first select box (to prevent duplicate entry). i also want to move item from right to left select box please suggest me optimized jQuery . Thanks.
UPDATE
if i want to use multiple select box on both side? then how do i use that?
more update
if i click on a item on rightselectbox and move it to left selectbox, and go further(post) then on right selectbox, there is nothing selected items?? what i need is on right selectbox, there all items shoud be always selected , otherwise what i need to do? after i move an item from right to left ,i again have to select rest of items on right selectbox and go further
solution for my update part
i used below code, please take a look and suggest me if somebody finds any mistake/error in this. Thanking You
jQuery('form').submit(function() {
jQuery('#accquiredMovies option').each(function(i) {
jQuery(this).attr("selected", "selected");
});
});