2013-09-28 16 views
-1

我正在使用struts 1.3。 我有一個問題和一組答案的jsp頁面。代碼片段如下。Struts 1.3獲取動態創建的值以供後臺驗證

<c:forEach items="${TestForm.testQuestions}" var="var" 
      varStatus="status" step="1" begin="0"> 
    <tr class="row"> 
     <td> 
      <c:out value="${var.question}" /> 
      <input type="hidden" value="<c:out value="var.qId"/>" 
        id="qstnId${status.index}"> 
     </td> 
     <td><input type="radio" value="A" name="opt${status.index}">A</td> 
     <td><input type="radio" value="B" name="opt${status.index}">B</td> 
     <td><input type="radio" value="C" name="opt${status.index}">C</td> 
     <td><input type="radio" value="D" name="opt${status.index}">D</td> 
    </tr> 
</c:forEach> 

有什麼辦法,我可以得到questionidqstnId${status.index}),並選擇value,將其存儲在FormBean的和後端驗證?

+4

您需要標題改成了問題。它與獲取元素的寬度無關。 – Archer

回答

0
// Get name 
var name = $("input[type='radio']:checked").attr("name"); 
// Remove non-digit characets 
var index = name.replace(/\D/g,''); 
+0

我需要將它們傳遞給後端java servlet進行驗證 – Arun

1

@Arun Raj檢出此代碼。我只是擴展了卡納的代碼。

// Get name 
var name = $("input[type='radio']:checked").attr("name"); 
// Remove non-digit characets 
var index = name.replace(/\D/g,''); 

$.ajax({ 
type: "POST", 
url: "Ur_Servlet_URL", 
data: { name: name,index: index } 
}) 
.done(function(msg) { 
//If you need anything to return. 
}); 

您可以像這樣在servlet中接收值。

String name=request.getParameter("name"); 
String index=request.getParameter("index"); 

希望這有助於..