Question

addBook.jsp

<display:table name="books" excludedParams="*" pagesize="25" class="table" export="false"  sort="external" id="book" requestURI="">              
 <display:column title="#">
   <input type="checkbox" name="book" value="${book.Id}"/>
 </display:column>                    
 <display:column title="bookName" style="width: 100%" >
   <c:out value="${book.name}"/>
 </display:column>
 <display:column title="bookDiscount" style="width: 100%" >
   <html:text property="discount"styleId="discount"/>                 
 </display:column>
</display:table>

bookAction.java

String[] percentage = request.getParameterValues("discount");
String[] cardTypeId = request.getParameterValues("book");

If I check a checkbox , I want to get that checked checkbox discount value using java in action class, so i can add the value in database. I have tried but not working. Could someone help me?

Was it helpful?

Solution 2

You are able to fetch the id of the check box na.Now compare the all id's of book with the check box id and find the position.Now the discount will be percentage[position]

ex:

<input id="${book.Id}" type="checkbox" name="book" value="${book.Id}"/>

in javascript

<script>
 var id = event.target.id;
 var position;
 var length = percentage.length();
 for(var i=0;i<length;i++){
   if( id == cardTypeId[i]){
    position = i;
    break;
   }
 }
 var percen = percentage[position];
</script>

OTHER TIPS

Ideally your checkbox, should be part of a Form. And then in your Action class, you need to fetch the checkbox values using the Form attributes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top