How to get each checkbox textfield value

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?

Answers


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>

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.


Need Your Help

execute shell, msgbox wont display

shell excel-vba batch-file text-files msgbox

I have an excel macro that creates and executes a batch file, which in turn executes a file that converts a pdf to text file. The macro then scans the text file for a keyword, and returns a value f...

.htaccess image redirect

php image apache .htaccess redirect

I've written a PHP class to add a watermark to an image, it works great when accessed via URL directly. I would like to "redirect" every image to my URL like so:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.