Solved

Selecting the specific record from the HTML table

Posted on 2008-10-07
9
256 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
  • 4
  • 3
  • 2
9 Comments
 
LVL 15

Accepted Solution

by:
dosth earned 500 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
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).

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now