2011-09-29 66 views
0

我有一個選擇框調用'ToLB',它從另一個選擇框中獲取值項目。我需要從'ToLB'中提取這些選定的值並將其打印在標籤上,這就是我如何做的,但顯然它不工作,因爲沒有任何錯誤信息,但沒有打印到標籤上,敬請建議,謝謝! :Javascript +從選擇框中打印值

選擇框:

<select multiple size="8" name="ToLB" style="width: 135px" onblur="javascript:dropValue6(this)"> 
</select> 

標籤:

QMType: <asp:Label ID="destinationQualMemType" runat="server" ></asp:Label > 

JavaScript函數:

function dropValue6(source) { 
    while (source.selectedIndex != -1) 
    { 
     if (source.selectedIndex != 0) arSelected.push(source.options[source.selectedIndex].value); 
     source.options[source.selectedIndex].selected = false; 

     var i; 
     for (i = 0; i < arSelected; i++) { 

      document.getElementById('<%= destinationSpendingType.ClientID %>').innerHTML = 
+ "\n" + document.getElementById('<%= destinationSpendingType.ClientID %>').innerHTML = arSelected[i].value; 
     } 
    } 

     } 

回答

2

呦你可以看看標有//***的線

function dropValue6(source) { 
    var arSelected = []; // *** 
    while (source.selectedIndex != -1) 
    { 
     if (source.selectedIndex != 0) arSelected.push(source.options[source.selectedIndex].value); 
     source.options[source.selectedIndex].selected = false; 

     var i; 
     for (i = 0; i < arSelected.length; i++) { // ***     
      document.getElementById('<%= destinationSpendingType.ClientID %>').innerHTML = arSelected[i]; // *** 
     } 
    }  
}