2011-02-13 99 views
0
1. Member Account Number<span class="bodyCopy"><font color="#ff0000"> * </font></span>: 
<html:select name="reDataForm" property="member.accountNumber" styleClass="formContent" 
     style="width:80px" onchange="showfield(this.options[this.selectedIndex].value)"> 
<html:options collection="<%= WorkConstants.Dropdowns.PACCT %>" property="value" 
      labelProperty="label" styleClass="formContent"/> 
</html:select> 

<div id="div1"></div> 

功能爲如下:其他選項 - 如何設置值?

<script type="text/javascript"> 
    function showfield(name){ 
     if(name=='Other') 
      document.getElementById('div1').innerHTML='<html:text name="reDataForm" property="member.accountNumber" styleClass="formContent" maxlength="9" size="9"/>'; 
     else 
      document.getElementById('div1').innerHTML=''; 
    } 
</script> 

的問題是:如果我選擇選項「其他」,文字下方的設計出現。但值member.accountNumber沒有設置到它。我可以看到帳號爲「其他」。而不是我在文本框中輸入的值。爲什麼?我該如何設置?

回答

3

您對客戶端和服務器端代碼感到困惑。 Struts標記<html:text>在服務器端呈現。在你的情況下,你試圖把這個自定義標籤放在客戶端(Javascript)。 Javascript基本上吐出了HTML行,並且您的瀏覽器無法解釋<html:text>是什麼,因爲這是服務器端自定義標記。

UPDATE

你需要做的是將文字作爲隱藏字段,這樣的Struts可以使自定義標籤和bean值: -

<html:hidden styleId="accountNumber" name="reDataForm" property="member.accountNumber"/> 

然後,在你的Javascript,你想從隱藏字段的值,並將其設置爲div1: -

<script type="text/javascript"> 
    function showfield(name){ 
     if(name=='Other') 
      document.getElementById('div1').innerHTML= document.getElementById('accountNumber').value; 
     else 
      document.getElementById('div1').innerHTML=''; 
    } 
</script> 
+0

讓我怎麼做呢?我應該在腳本中使用 RMa 2011-02-13 03:06:12

相關問題