Develop PHP Website for Learning Web Design Free Online
  Home   |   Forums   |   DevCMS
  Join   |   Log In
 
 


Tutor at Develop PHP
Switch options between lists
Programming Category: jQuery

Author: pch      Added: Jul 08, 2010      Views: 453    
Tweet This Page  Post page to Facebook  Post page to Facebook
You might have seen before on websites where you have two or more dropdown lists where you can switch the options between the dropdowns. This tutorial will cover the little code required to get this basic but usefull trick to work. 

jQuery

Learn HTML
$(function(){
$("#switchAdmin").click(function(){
$("#adminDropDown option:selected").remove().appendTo("#userDropDown");
});
$("#switchUser").click(function(){
$("#userDropDown option:selected").remove().appendTo("#adminDropDown");
});
});

Actually if you've read any previous tutorial about jQuery, everything above is familiar.

$("#adminDropDown option:selected")
This will get the option that is currently selected in the dropdown #adminDropDown.

.remove().appendTo("#userDropDown")
This will remove the selected option (<option></option>) from the current dropdown and add it to the
drop down with an id of #userDropDown.

HTML

Learn HTML
<select id="adminDropDown">
<option>Edit Pages</option>
......
</select><input type="button" id="switchAdmin" value="Visible to users" /><br /><br />
<select id="userDropDown">
<option>Homepage</option>
......
</select><input type="button" id="switchUser" value="Visible to admin" />


Comment on Switch options between lists

 
 
Arbitrary Links and Archives
Home
Active Forums
Members
SIte News
Link To Us
Gear
2009 Forum Archive
Programming Courses
Learn HTML
Learn CSS
Learn PHP
Learn MySQL
Learn Javascript
Learn jQuery
Learn ActionScript 3.0
Learn Java
Learn XML
DevelopPHP Requires Flash Player
Get Adobe Flash player
___________________________________________

Terms of Use  •  Privacy  •  Admin Notes

©2010 developphp.com   |   Powered By FlashBuildingHolder