?
Solved

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

Posted on 2003-03-11
2
Medium Priority
?
216 Views
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>
      </tr>
      <tr>
        <td width="40%" bgcolor=#f0f0f0 align="center" valign="top" height="22">
          <font face=Verdana, Arial, Helvetica, sans-serif size="2" color=black>Item
          Name</font></td>
        <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>
      </tr>
      <% double totalprice=0.00; %>
      <% for(int jj=0;jj<itemcheckbox.length;jj++) { %>
      <tr>
        <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$
      </tr>
        <% double price =0.00;
           price = Float.valueOf((String)offer_price[jj]).floatValue();
           totalprice += price; %>

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

    </table>
    <!------------- End Item List ----------------->
  </div>


Thank you in advance.

zamir
0
Comment
Question by:zamirjalil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
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="";

/*****************************************************/
%>
<center>

<form method="post" name=formnewquote>

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

<h3>Item List</h3>

<!-- Start List of Item(s) -->
<table>
  <tr>
    <th><div align="center"></div></td>
    <th>Item Name</td>
    <th>Qty</td>
    <th>Unit</td>
    <th>Unit Price</td>
    <th>Offer Price</td>
  </tr>
  <%
int ii = 0;
if (itemname!=null) {
  for (int k=0;k<isChecked.length;k++) {
     if ( ! ( doDelete && isChecked[k] ) ) {
       %>
  <tr>
    <td> <div align="center">
        <input type="checkbox" name="chkbox" value="<%=ii%>">
      </div></td>
    <td><div align="center">
        <input name="itemname" type=text value="<%=itemname[k]%>" size="17">
      </div></td>
    <td><div align="center">
        <input name="qty" type=text value="<%=qty[k]%>" size="5">
      </div></td>
    <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>
        </select>
      </div></td>
    <td><div align="center">
        <input name="unitprice" type=text value="<%=unitprice[k]%>" size="8">
      </div></td>
    <td><div align="center">
        <input name="offerprice" type=text value="<%=offerprice[k]%>" size="8">
      </div></td>
  </tr>
  <%
         ii ++;
     }
  } //for
} //if

if( "Add".equals( action )  || itemname == null ) {
%>
  <tr>
    <td><div align="center">
        <input type="checkbox" name="chkbox" value="<%=ii%>">
      </div></td>
    <td><div align="center">
        <input name="itemname" type="text" size="17">
      </div></td>
    <td><div align="center">
        <input name="qty" type="text" size="5">
      </div></td>
    <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>
        </select>
      </div></td>
    <td><div align="center">
        <input name="unitprice" type="text" size="8">
      </div></td>
    <td><div align="center">
        <input name="offerprice" type="text" size="8">
      </div></td>
  </tr>
  <% } %>
  <td colspan="6">
      <a href="javascript:checkall('formnewquote','chkbox',true)">All</a>/<a
      href="javascript:checkall('formnewquote','chkbox',false)">None</a>
  <input type=submit value="Delete Selected Item" name="action"></td>
  </tr>
  <tr>
    <td colspan="6"><input type=submit value="Add" name="action" ></td>
  </tr>
</table>
</form>
</center>
0
 

Author Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

762 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