2016-04-17 16 views
0
<html> 
<head> 
<script type="text/javascript"> 

function changeFunc() { 
var selectBox = document.getElementById("selectBox"); 
var selectedValue = selectBox.options[selectBox.selectedIndex].value; 
alert(selectedValue); 
} 

</script> 
</head> 

<body> 
<select id="selectBox" onchange="changeFunc();"> 
<option value="1">Option #1</option> 
<option value="2">Option #2</option> 
</select> 
</body> 
</html> 

我們可以得到的SelectedValue早在JSP作爲的onChange參數,並通過它來形成一個隱藏的變量,並把它回支柱作用?獲取JavaScript計算值Struts動作

+1

的可能的複製[如何獲得形式的JavaScript計算值(http://stackoverflow.com/questions/36671921/how-to-get-javascript-calculated在表單中的值) –

+0

*倒票最喜歡的* :) –

+0

我不知道這個問題實際上是什麼 - 將值放入隱藏的窗體屬性,你就完成了。 –

回答

0

我已經加入jQuery的線來填充JSP

所以每當單選按鈕被點擊JSP 隱藏字段的隱藏字段的值,jQuery的幫助我填充我的隱藏字段的值。

它的工作,感謝

<html:hidden name="annualPremSizeCreditForm" property="selectedRadioButtonID" value=""/> 

    var radioButtonIdDesc = $('input[type=radio][name=radioButtons]:checked').attr('id'); 
         if((radioButtonIdDesc).indexOf("fifteenPercentRadio") != -1){ 
          $('input[name=selectedRadioButtonID]').val("fifteenPercentRadio"); 
         } 
         if((radioButtonIdDesc).indexOf("tenPercentRadio") != -1){ 
          $('input[name=selectedRadioButtonID]').val("tenPercentRadio"); 
         }