Results 1 to 6 of 6

Thread: JavaScript: Add selected items of listbox to other listbox?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091

    JavaScript: Add selected items of listbox to other listbox?

    I want to place to listboxes (drop-down with multi-select on) on a web page. I want to provide 2 buttons, "Add To List", "Remove From List". When the user clicks the "Add To List" button, I want the selected items in listbox1 to move over to listbox2. When they click on "Remove From List", I want the selected items in listbox2 to move back over to listbox1. Is this possible with JavaScript?

    Any help or examples would be greatly appreciated.

    Dan

    Visual Studio 2010

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: JavaScript: Add selected items of listbox to other listbox?

    Originally posted by dbassettt74
    I want to place to listboxes (drop-down with multi-select on) on a web page. I want to provide 2 buttons, "Add To List", "Remove From List". When the user clicks the "Add To List" button, I want the selected items in listbox1 to move over to listbox2. When they click on "Remove From List", I want the selected items in listbox2 to move back over to listbox1. Is this possible with JavaScript?

    Any help or examples would be greatly appreciated.

    Dan
    Yes Dan, its very much possible with JavaScript. Here is an example that i used in one of my project.

    VBF does not allow html file to be uploaded so i changed the extention of the file to .txt, change it back to .html after you download.

    Hope this helps.

    Danial
    Attached Files Attached Files
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Thanks, it worked perfectly!!

    Visual Studio 2010

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Is there anyway to get away from using the "temp" object to store the add items? Like maybe an array instead? I don't want to show an empty listbox on the screen. Can you help me with this?

    Visual Studio 2010

  5. #5
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    Hi

    here's an example is just did on the fly !

    i did'nt put any remove or reset !

    Code:
    <HTML>
    <script language=javascript>
    	function addIt(newValue, newText){
    		var newOption = new Option(newText,newValue,false,false);
    		document.forms[0].dest.options[document.forms[0].dest.length] = newOption;	
    	}
    
    </script>
    <form>
    <SELECT name=src size=8 onChange="addIt(this[this.selectedIndex].value,this[this.selectedIndex].text);">
    	<OPTION VALUE=1>Item 1</OPTION>
    	<OPTION VALUE=2>Item 2</OPTION>	
    	<OPTION VALUE=3>Item 3</OPTION>	
    	<OPTION VALUE=4>Item 4</OPTION>	
    	<OPTION VALUE=5>Item 5</OPTION>	
    </SELECT>
    
    <SELECT name=dest size=8>
    
    </SELECT>
    </form>
    </HTML>
    good luck

  6. #6
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by dbassettt74
    Is there anyway to get away from using the "temp" object to store the add items? Like maybe an array instead? I don't want to show an empty listbox on the screen. Can you help me with this?
    Hi Dan,
    You can use style tag to make the temp listbox invisible,
    <select name=temp size=0 style="visibility:hidden"></select>

    And yes indeed you can use array, you will need a multi dimentional array to store both the value and text of the each item(notice that my code allows you to move multiple items from one listbox to another).

    I havent used multi dimenational array in JavaScript that much and i was in a hurry thats why i choose to use a temp lisbox instead. You could give it a go if you wish. i will give it a try if i get time.

    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width