How to get the checkbox array value passed from another page?

Posted on 2003-03-11
Medium Priority
Last Modified: 2010-04-01
Hi experts,

I have a page with a list of item need to be selected in order to proceed to the next page. And the next page should be displayed all the selected value, in my case the values are itemname,unit,quantity and offer_price. To do this, I check the checkbox parametervalues in the for statement, to know how many item was selected and then display the value of itemname,unit,quantity and offerprice. The problem is when I select the first row, it will display the corrent values of itemname...etc, but if I select the second or third row from itemlist, it still give a the value of the first row. Please help me how to solve this.

Below is the code:

  <div align="center"> <br>
    <!-- Start Item List -->
        String[] itemcheckbox =  request.getParameterValues("itemcheckbox");
        String[] itemname  = request.getParameterValues("itemname");
        String[] unit  = request.getParameterValues("unit");
        String[] quantity  = request.getParameterValues("quantity");
        String[] offer_price  = request.getParameterValues("price");

    <table border="0" width=600 cellpadding="3">
      <tr bgcolor="#cecece">
        <td height="22" colspan="4" align="center" valign="top"><font face=Verdana, Arial, Helvetica, sans-serif size="2" col$
          List </strong></font></td>
        <td width="40%" bgcolor=#f0f0f0 align="center" valign="top" height="22">
          <font face=Verdana, Arial, Helvetica, sans-serif size="2" color=black>Item
        <td width="18%" bgcolor=#f0f0f0 align="center" valign="top" height="22">
          <font size="2" face="Verdana, Arial,Helvetica, sans-serif">Quantity</font></td>
        <td bgcolor=#f0f0f0 align="center" width="19%" valign="top"> <font face="Verdana, Arial, Helvetica, sans-serif" size=$
        <td bgcolor=#f0f0f0 align="center" width="23%" valign="top" height="22">
          <font face=Verdana, Arial, Helvetica, sans-serif size="2" color=black>Price
          (RM) </font></td>
      <% double totalprice=0.00; %>
      <% for(int jj=0;jj<itemcheckbox.length;jj++) { %>
        <td align="center" valign="top" height="22"><%=itemname[jj]%><input type="hidden" name="itemname" value="<%=itemname[$
        <td align="center" valign="top" height="22"><%=quantity[jj]%><input type="hidden" name="quantity" value="<%=quantity[$
        <td align="center" valign="top" height="22"><%=unit[jj]%><input type="hidden" name="unit" value="<%=unit[jj]%>"></td>
        <td align="center" valign="top" height="22"><%=offer_price[jj]%><input type="hidden" name="price" value="<%=offer_pri$
        <% double price =0.00;
           price = Float.valueOf((String)offer_price[jj]).floatValue();
           totalprice += price; %>

      <%} %>
      <% java.text.DecimalFormat df = new java.text.DecimalFormat("#.00"); %>
        <td height="22" colspan="3" align="center" valign="top"><div align="right">
                        <font face=Verdana, Arial, Helvetica, sans-serif size="2" color=black>
        <td align="center" valign="top" height="22"><%=df.format(totalprice)%>
        <input type="hidden" name="totalprice" value="<%=df.format(totalprice)%>"/></td>

    <!------------- End Item List ----------------->

Thank you in advance.

Question by:zamirjalil
LVL 14

Accepted Solution

kennethxu earned 80 total points
ID: 8116406
check and try out this example, then you'll get the idea.
let me know if you have further enquires.
String action=request.getParameter("action");
String[] itemname = request.getParameterValues("itemname");
String[] qty =  request.getParameterValues("qty");
String[] unit = request.getParameterValues("unit");
String[] unitprice = request.getParameterValues("unitprice");
String[] offerprice = request.getParameterValues("offerprice");
String[] chkbox = request.getParameterValues("chkbox");

boolean doDelete = "Delete Selected Item".equals( action );
boolean[] isChecked = null;

if( itemname != null ) isChecked = new boolean[ itemname.length ];
if( doDelete && chkbox != null ) {
  for( int jj = 0; jj<chkbox.length; jj ++ ) {
       int index = Integer.parseInt( chkbox[jj] );
       // out.println( "got " + index );
       isChecked[index] = true;

if (action==null) action="";


<form method="post" name=formnewquote>

<% //if (action.equals("Submit")){ %>
<%  //@include file = "process_nq1.jsp"%>
<% //} %>

<h3>Item List</h3>

<!-- Start List of Item(s) -->
    <th><div align="center"></div></td>
    <th>Item Name</td>
    <th>Unit Price</td>
    <th>Offer Price</td>
int ii = 0;
if (itemname!=null) {
  for (int k=0;k<isChecked.length;k++) {
     if ( ! ( doDelete && isChecked[k] ) ) {
    <td> <div align="center">
        <input type="checkbox" name="chkbox" value="<%=ii%>">
    <td><div align="center">
        <input name="itemname" type=text value="<%=itemname[k]%>" size="17">
    <td><div align="center">
        <input name="qty" type=text value="<%=qty[k]%>" size="5">
    <td><div align="center">
      <select name="unit" >
          <option value="kg" <% if ("unit[k]".equals("kg")) out.println("selected");%>>Kg</option>
          <option value="ctn" <% if ("unit[k]".equals("kg")) out.println("selected");%>>Cartons</option>
          <option value="pkt" <% if ("unit[k]".equals("kg")) out.println("selected");%>>Packet</option>
          <option value="tons" <% if ("unit[k]".equals("kg")) out.println("selected");%>>Tons</option>
    <td><div align="center">
        <input name="unitprice" type=text value="<%=unitprice[k]%>" size="8">
    <td><div align="center">
        <input name="offerprice" type=text value="<%=offerprice[k]%>" size="8">
         ii ++;
  } //for
} //if

if( "Add".equals( action )  || itemname == null ) {
    <td><div align="center">
        <input type="checkbox" name="chkbox" value="<%=ii%>">
    <td><div align="center">
        <input name="itemname" type="text" size="17">
    <td><div align="center">
        <input name="qty" type="text" size="5">
    <td><div align="center">
      <select name="unit">
          <option value="kg">Kg</option>
          <option value="ctn">Cartons</option>
          <option value="pkt">Packet</option>
          <option value="tons">Tons</option>
    <td><div align="center">
        <input name="unitprice" type="text" size="8">
    <td><div align="center">
        <input name="offerprice" type="text" size="8">
  <% } %>
  <td colspan="6">
      <a href="javascript:checkall('formnewquote','chkbox',true)">All</a>/<a
  <input type=submit value="Delete Selected Item" name="action"></td>
    <td colspan="6"><input type=submit value="Add" name="action" ></td>

Author Comment

ID: 8134971
kenn, I think 20 point is too much you man..
just kidding  :)

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

We can see that the frameworks like React Native and PhoneGap make the development process of the applications relatively less expensive and more accessible than the development would cost when written in the native language for the platform.
In this article the author has highlighted some of the best features of best data recovery brands that are going to rock in 2018 (in the author's humble opinion).
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question