?
Solved

Selecting the specific record from the HTML table

Posted on 2008-10-07
9
Medium Priority
?
264 Views
Last Modified: 2012-05-05
Hi experts,

I was trying to generate the product list from the database and then display them in the tabular form using HTML tables with the Add button in front of every row. Now what I need to do is that whenever the user clicks on the Add button, the corresponding record should give me its unique value for which I am using hidden field. Here is the code snippet,

<table border="1">
<% mydb.connect();
                     rs = mydb.query("SELECT * FROM Product");
                     while (rs.next()) {
                  %>
                  <tr>
                  <!-- <td><%= rs.getString("Product_Code") %></td>  -->
                        <td><%= rs.getString("Product_Category") %></td>
                        <td><%= rs.getString("Product_Desc") %></td>
                        <td align="right"><%= rs.getString("Product_Price") %></td>
                        <td>
                              <input type="text" id="qty" name="qty" maxlength="3" size="3">
                              <input type="hidden" id="pk" name="pk" value=<%= rs.getString("Product_Code")%>>
                        </td>
                        <td>
                              <img src="images/addtocart.gif" alt="Cart" border="0" height="40" width="40" onclick="CheckQty();return">
                        </td>
                  </tr>
                  <% } %>
            </table>

0
Comment
Question by:RohitGupta2008
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 15

Accepted Solution

by:
dosth earned 1500 total points
ID: 22661929
<table border="1">
<% mydb.connect();
                     rs = mydb.query("SELECT * FROM Product");
                     while (rs.next()) {
                  %>
                  <tr>
                  <!-- <td><%= rs.getString("Product_Code") %></td>  -->
                        <td><%= rs.getString("Product_Category") %></td>
                        <td><%= rs.getString("Product_Desc") %></td>
                        <td align="right"><%= rs.getString("Product_Price") %></td>
                        <td>
                              <input type="text" id="qty" name="qty" maxlength="3" size="3">
                              <input type="hidden" id="pk" name="pk" value=<%= rs.getString("Product_Code")%>>
                        </td>
                        <td>
                              <a href="" onClick="javascript:CheckQty('<%=rs.getString("Product_Code")%>');return"><img src="images/addtocart.gif" alt="Cart" border="0" height="40" width="40"></a>
                        </td>
                  </tr>
                  <% } %>
            </table>
0
 

Author Comment

by:RohitGupta2008
ID: 22662030
adding the parameter to CheckQty() function really works for me and I am able to get the value of the selected product. If you observe the code, I have textbox with every record so that user can enter the value for the qty. How can I pick that qty value of the selected product???Please help...
0
 
LVL 15

Expert Comment

by:dosth
ID: 22662207
<table border="1">
<% mydb.connect();
                     rs = mydb.query("SELECT * FROM Product");
                 idx=0
                     while (rs.next()) {
                  %>
                  <tr>
                  <!-- <td><%= rs.getString("Product_Code") %></td>  -->
                        <td><%= rs.getString("Product_Category") %></td>
                        <td><%= rs.getString("Product_Desc") %></td>
                        <td align="right"><%= rs.getString("Product_Price") %></td>
                        <td>
                              <input type="text" id="qty" name="qty" maxlength="3" size="3">
                              <input type="hidden" id="pk" name="pk" value=<%= rs.getString("Product_Code")%>>
                        </td>
                        <td>
                              <img src="images/addtocart.gif" alt="Cart" border="0" height="40" width="40" onclick="CheckQty('<%=idx%>');return">
                        </td>
                  </tr>
                  <% } %>
            </table>

on your js function, you will get the qty as array of object, get the index you passed to get the values
0
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 

Author Comment

by:RohitGupta2008
ID: 22662306
This is fine but still I am not getting the value of qty. Can you please provide the snippet for js on how to retreive qty as array of object.
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22665133
javascript --
var quantity = document.getElementById('qty').innerHTML;

or if a form value --
var quantity = document.form_name.qty.value;

the quantity is now in the javascript variable "quantity"
Remember, if using inner HTML, you have to convert to number --

var qty = ParseInt(quantity);
0
 

Author Comment

by:RohitGupta2008
ID: 22665838
Thanx scrathcyboy.
but if you check the previous comment by dosth where we need to pass the qty as argument to the js function where I can use qty as the array of object. I want help on using qty as the array of object so that I can extract the value of the qty of the selected product.
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22666209
my code gets it without an array.  THere is no array in your code.

"whenever the user clicks on the Add button, the corresponding record should give me its unique value for which I am using hidden field. Here is the code snippet,"

That is NOT an array, you are asking for the quantity one by one, per click.
0
 

Author Comment

by:RohitGupta2008
ID: 22666225
Sorry for not explaining my question well. Actually that was the first question which is already resolved. After resolving first one then the next problem was to get the corresponding value of qty. The solution you gave, I already did that but that wasnt working thats why i put the question here...
0
 
LVL 15

Expert Comment

by:dosth
ID: 22718649
thanks for the points
0

Featured Post

Industry Leaders: 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

This article discusses how to create an extensible mechanism for linked drop downs.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

765 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