faqts : Computers : Programming : Languages : JavaScript : Forms : SELECT

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

24 of 44 people (55%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How do I populate a second multiple select by selecting options in a first multiple select?

Nov 25th, 2004 04:31
Hans Decheveir, z - design,


// To copy multiple select box values from one multiple select box to 
// another multiple select box:
function copySelectValues() {
    var selSource = document.formName.selSourceName;
    var selTo = document.formName.selToName;
    for (var i = 0; i < selSource.options.length; i++) {
        if (selSource.options[i].selected) {
      	    var newOption = new Option(selSource.options[i].text, 
selSource.options[i].value);	
            selTo.options[selTo.options.length] = newOption; } } 
// Use the function below to delete options from selSource after the 
// copying
    deleteOptions(selSource)
}
function deleteOptions(selDelete) {
    for (var i = 0; i < selDelete.options.length; i++) {  	
        if (selDelete.options[i].selected) {        		
	    selDelete.options[i] = null;
	    i=-1 } } }