Need Help w/ Drag&Drop in Listbox

melvinlui's Avatar, Join Date: Jan 2010
Newbie Member
Hi,

I've just created a dynamic listbox in JSP using the <SELECT> tag. However, i need to come up with a code to allow the users to drag and drop the items in the listbox to rearrange them in the order the user prefers.

Is this possible by using JSP? if so, how can it be done? can anyone shed a light or two?

Melvin
venami's Avatar, Join Date: Dec 2008
Ambitious contributor
These can be done using JavaScript easily. But can you explain more on your need?
melvinlui's Avatar, Join Date: Jan 2010
Newbie Member
Hi Venami,

Thank you for your reply.
What i have is a listbox containing column headers that i have extracted from a database, and i need to be able to rearrange them according to the order that i want and save it back into the database. The problem is i do not know how to do a drag and drop for a list box. below will be an example of how i have done it:

Code:
<SELECT NAME='userId'>
<%
	String sqlUserIdSelect = "SELECT DISTINCT UserId FROM kplustp..ProfilingGridFieldUser";
	
	stmt = con.createStatement(); 
	resultSet = stmt.executeQuery( sqlUserIdSelect );

	int userRowNum = resultSet.getRow();
	int userColNum = resultSet.getMetaData().getColumnCount();
%>
<%
         int a=1;
   	 while ( resultSet.next() ) 
	{
	      for( int b=1 ; b<=userColNum ; b++ ) 
		{
	          String userColResult = resultSet.getString( b );

		  out.println( "<OPTION VALUE='" + userColResult + "' ");
			if (userId!=null && request.getParameter("userId").equals(userColResult))
				{out.println("SELECTED");}
		  out.println(">" + userColResult + "</OPTION>" );
		}
	}
%>
</SELECT>
Basically it is just a <SELECT> listbox, but i need to move the elements within it up and down by drag and drop to rearrange them. if still not clear, maybe i could upload some pictures to show you a clearer example?