-1

I am using struts 1.3. I have a jsp page with a question and set of answers. A code fragment is given below.

<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>

Is there any way I can get the questionid (qstnId${status.index}) and selected value, store it in a formbean and validate in back end?

Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
Arun
  • 3,701
  • 5
  • 32
  • 43

2 Answers2

1

@Arun Raj Checkout this code. I am just extending Karna's Code.

// 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.
});

You can receive the values in servlet like this.

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

Hope this helps..

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
0
// Get name
var name = $("input[type='radio']:checked").attr("name");  
// Remove non-digit characets
var index = name.replace(/\D/g,'');
Ajinkya
  • 22,324
  • 33
  • 110
  • 161