Learn how to a build a cloud-first strategyRegister Now


Getting Values from Dual List Box

Posted on 2012-08-17
Medium Priority
Last Modified: 2012-08-17
I'm using the following javascript function in a dual list box setup where the selected items in srcList and added to the destList, which is then submitted. Everything works fine except the text is being posted instead of the valueS for the selected items. I want the text to show in the list box as it currently is, but I just want the values to post when the form is submitted.


function moveDualList( srcList, destList, moveAll ) {

	if ( ( srcList.selectedIndex == -1 ) && ( moveAll == false ) )

newDestList = new Array( destList.options.length );
var len = 0;

	for( len = 0; len < destList.options.length; len++ ) {
		if ( destList.options[ len ] != null )
		newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );

	for( var i = 0; i < srcList.options.length; i++ ) { 
		if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
		newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );

	newDestList.sort( compareOptionValues ); // BY VALUES
		for ( var j = 0; j < newDestList.length; j++ ) 	{
			if ( newDestList[ j ] != null )
			destList.options[ j ] = newDestList[ j ];

	for( var i = srcList.options.length - 1; i >= 0; i-- ) { 
		if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
		srcList.options[i] = null;

} // End of moveDualList()

Open in new window

Question by:abgtemp
LVL 60

Accepted Solution

Julian Hansen earned 1200 total points
ID: 38305565
Works for me - used the attached code

Author Comment

ID: 38305958
Thanks. I had the same code, but I was calling another function to sort the text values in the destination list box was throwing everything off.  I removed that and everything is working.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month20 days, 21 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question