473,587 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DOM Table: how to get the correct row no

10 New Member
Hi,

I'm working on a program using javascript to create a dynamic table. Initially was developing this in IE environment. It work fine, but realise that it doesn't work on Mozilla FireFox.

So I change it to using DOM Table to construct the table. But now I can't get the correct row no from the "Browse" button that I clicked on. It will only return the total number of rows instead of the currect row no I clicked on.

On previous working version, I make use of count2 to denote the row no. But after I've changed the code, count2 only shows the total row.

Was wondering if anyone here are able to help.

Refer to the code below, I didn't include all the codes as the program was too large:
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <TITLE>Customer Service</TITLE>
  4. <SCRIPT LANGUAGE='javascript'>var pageLoaded=false;
  5.                     function loadvar() {
  6.                         pageLoaded=true;
  7.                     }
  8.                     function searchProduct(form1, field1, field2, field3, idx) {
  9.                         if (pageLoaded==false) {
  10.                             window.alert("WOL5859: Page has not finished loading");
  11.                         }
  12.                         else {
  13.                             window.alert("This is row no:"+idx);                            
  14.                         }
  15.                     }                    
  16.  
  17. var count2 = 0;
  18. function addReplace(tableID)
  19. {
  20. var tbody = document.getElementById(tableID).getElementsByTagName("TBODY")[0];
  21. var row = document.createElement("TR");
  22. var td1 = document.createElement("TD");
  23. td1.className = "l1TD";
  24. td1.align = "center";
  25. td1.appendChild (replaceTD7());
  26. var td2 = document.createElement("TD");
  27. td2.className = "l1TD";
  28. td2.appendChild (replaceTD5());
  29. td2.appendChild (replaceTD6());
  30. td2.appendChild(document.createTextNode("New"));
  31. var td3 = document.createElement("TD");
  32. td3.className = "l1TD";
  33. td3.appendChild (replaceTD9());
  34. var td4 = document.createElement("TD");
  35. td4.className = "l1TD";
  36. td4.appendChild (replaceTD1());
  37. td4.appendChild (replaceTD4());
  38. var td5 = document.createElement("TD")
  39. td5.className = "l1TD";
  40. td5.appendChild (replaceTD2());
  41. var td6 = document.createElement("TD");
  42. td6.className = "l1TD";
  43. td6.appendChild (replaceTD3());
  44. var td7 = document.createElement("TD");
  45. td7.className = "l1TD";
  46. td7.appendChild (replaceTD10());
  47. var td8 = document.createElement("TD");
  48. td8.className = "l1TD";
  49. td8.appendChild (replaceTD11());
  50. var td9 = document.createElement("TD");
  51. td9.className = "l1TD";
  52. td9.appendChild (replaceTD8());
  53. row.appendChild(td1);
  54. row.appendChild(td2);
  55. row.appendChild(td3);
  56. row.appendChild(td4);
  57. row.appendChild(td5);
  58. row.appendChild(td6);
  59. row.appendChild(td7);
  60. row.appendChild(td8);
  61. row.appendChild(td9);
  62. tbody.appendChild(row);
  63. count2 += 1;
  64. } // addReplace
  65. function replaceTD1()
  66. {
  67. var newField = document.createElement("input");
  68. newField.type = "text";
  69. newField.name = "in_product2";
  70. newField.size = 30;
  71. newField.maxlength = 30;
  72. return newField;
  73. }
  74. function replaceTD4()
  75. {
  76. var newField = document.createElement("input");
  77. newField.type = "button";
  78. newField.value = "Browse ";
  79. newField.onclick = function() {searchProduct(document.form1, document.form1.in_product2, document.form1.in_description2, document.form1.in_unit_price2,count2)};
  80. return newField;
  81. }
  82. function replaceTD2()
  83. {
  84. var newField = document.createElement("input");
  85. newField.type = "hidden";
  86. newField.name = "in_description2";
  87. return newField;
  88. }
  89. function replaceTD3()
  90. {
  91. var newField = document.createElement("input");
  92. newField.type = "text";
  93. newField.name = "in_qty2";
  94. newField.onblur = function() { calVal2(this.form, count2)};
  95. return newField;
  96. }
  97. function replaceTD5()
  98. {
  99. var newField = document.createElement("input");
  100. newField.type = "hidden";
  101. newField.name = "in_status2";
  102. newField.value = "new";
  103. return newField;
  104. }
  105. function replaceTD6()
  106. {
  107. var newField = document.createElement("input");
  108. newField.type = "hidden";
  109. newField.name = "in_rowid2";
  110. newField.value = count2;
  111. return newField;
  112. }
  113. function replaceTD7()
  114. {
  115. var newField = document.createElement("input");
  116. newField.type = "checkbox";
  117. newField.name = "in_selected_rowid2";
  118. newField.value = count2;
  119. return newField;
  120. }
  121. function replaceTD8()
  122. {
  123. var newField = document.createElement("select");
  124. newField.name = "in_trans_code2";
  125. newField.options[0] = new Option("All","%");
  126. newField.options[1] = new Option("IS=Issuable","IS");
  127. newField.options[2] = new Option("RE=REJECTED","RE");
  128. newField.options[3] = new Option("NM=Normal","NM");
  129. return newField;
  130. }
  131. function replaceTD9()
  132. {
  133. var newField = document.createElement("select");
  134. newField.name = "in_stock_loc2";
  135. newField.options[0] = new Option("1-1-1-1","1-1-1-1");
  136. newField.options[1] = new Option("1-1-2-1","1-1-2-1");
  137. newField.options[2] = new Option("1-1-3-1","1-1-3-1");
  138. newField.options[3] = new Option("1-1-4-1","1-1-4-1");
  139. newField.options[4] = new Option("RCPT","RCPT");
  140. return newField;
  141. }
  142. function replaceTD10()
  143. {
  144. var newField = document.createElement("input");
  145. newField.type = "text";
  146. newField.name = "in_unit_price2";
  147. newField.onblur= function() {calVal2(this.form,count2)};
  148. return newField;
  149. }
  150. function replaceTD11()
  151. {
  152. var newField = document.createElement("input");
  153. newField.type = "text";
  154. newField.name = "in_amount2";
  155. return newField;
  156. }
  157. </script>
  158. </HEAD>
  159.  
  160. <BODY class="contentBody" onLoad="loadvar();"link="#0000CC" vlink="#0000CC" alink="#0000CC">
  161.  
  162.         <style type="text/css">
  163.         <!--
  164.          .titletabborder {
  165.             background-color: #004080;
  166.             height: 22px;
  167.             border: 1px solid #FFFFFF;
  168.         }
  169.         -->
  170.         </style>       
  171.  
  172.         <BR>
  173.  
  174. <tr><td><FORM ACTION="WWW_RMA_CUSTOMER_PK.proc_customer3" METHOD="POST" name="form1">
  175. <BR>
  176. <INPUT TYPE="hidden" NAME="in_stock_loc2" VALUE="dummy">
  177. <INPUT TYPE="hidden" NAME="in_product2" VALUE="dummy">
  178. <INPUT TYPE="hidden" NAME="in_unit_price2" VALUE="dummy">
  179. <INPUT TYPE="hidden" NAME="in_qty2" VALUE="dummy">
  180. <INPUT TYPE="hidden" NAME="in_lot_no2" VALUE="dummy">
  181. <INPUT TYPE="hidden" NAME="in_serial_no2" VALUE="dummy">
  182. <INPUT TYPE="hidden" NAME="in_exp_date2" VALUE="dummy">
  183. <INPUT TYPE="hidden" NAME="in_aoptchar1_2" VALUE="dummy">
  184. <INPUT TYPE="hidden" NAME="in_aoptchar2_2" VALUE="dummy">
  185. <INPUT TYPE="hidden" NAME="in_aoptchar3_2" VALUE="dummy">
  186. <INPUT TYPE="hidden" NAME="in_aoptchar4_2" VALUE="dummy">
  187. <INPUT TYPE="hidden" NAME="in_aoptchar5_2" VALUE="dummy">
  188. <INPUT TYPE="hidden" NAME="in_aoptchar6_2" VALUE="dummy">
  189. <INPUT TYPE="hidden" NAME="in_aoptnum1_2" VALUE="dummy">
  190. <INPUT TYPE="hidden" NAME="in_aoptnum2_2" VALUE="dummy">
  191. <INPUT TYPE="hidden" NAME="in_aoptnum3_2" VALUE="dummy">
  192.  
  193. <INPUT TYPE="hidden" NAME="in_aoptnum4_2" VALUE="dummy">
  194. <INPUT TYPE="hidden" NAME="in_aoptdate1_2" VALUE="dummy">
  195. <INPUT TYPE="hidden" NAME="in_aoptdate2_2" VALUE="dummy">
  196. <INPUT TYPE="hidden" NAME="in_description2" VALUE="dummy">
  197. <INPUT TYPE="hidden" NAME="in_trans_code2" VALUE="dummy">
  198. <INPUT TYPE="hidden" NAME="in_amount2" VALUE="dummy">
  199. <INPUT TYPE="hidden" NAME="in_status2" VALUE="dummy">
  200. <INPUT TYPE="hidden" NAME="in_rowid2" VALUE="dummy">
  201. <INPUT TYPE="hidden" NAME="in_selected_rowid2" VALUE="dummy">
  202. <fieldset>
  203. <legend>
  204. <LABEL CLASS="formEntryLblOpt"><b>Spare Parts Requested</b></LABEL>
  205. </legend>
  206. <BR>
  207. <TABLE  border="0" cellpadding="2" cellspacing="1" class="browseTable" id="replaceTab">
  208. <TR>
  209.  
  210. <TD NOWRAP  CLASS="l1TH" >Delete</TD>
  211. <TD NOWRAP  CLASS="l1TH" >Sequence No</TD>
  212. <TD NOWRAP  CLASS="l1TH" >Stock Location</TD>
  213. <TD NOWRAP  CLASS="l1TH" >Spare Part Code</TD>
  214. <TD NOWRAP  CLASS="l1TH" >Description</TD>
  215. <TD NOWRAP  CLASS="l1TH" >Quantity Requested</TD>
  216. <TD NOWRAP  CLASS="l1TH" >Unit Price</TD>
  217. <TD NOWRAP  CLASS="l1TH" >Amount</TD>
  218. <TD NOWRAP  CLASS="l1TH" >Stock Status Code</TD>
  219.  
  220. </TR>
  221. </TABLE>
  222. <INPUT TYPE="button" VALUE="Add Row" class="defaultButton" onClick="addReplace('replaceTab');">
  223. <BR>
  224. </fieldset>
  225. <BR>
  226. <BR>
  227. <P>
  228. <CENTER>
  229. <INPUT TYPE="button" VALUE="Delete" class="defaultButton" onClick="submitButton('delete');">
  230. &nbsp;&nbsp;&nbsp;
  231. <INPUT TYPE="button" VALUE="Save" class="defaultButton" onClick="submitButton('submit');">
  232. &nbsp;&nbsp;&nbsp;
  233. <INPUT TYPE="button" VALUE="Next &gt;&gt;" class="defaultButton" onClick="submitButton('next_step');">
  234. &nbsp;&nbsp;&nbsp;
  235. <INPUT TYPE="reset" VALUE="Reset" class="defaultButton" class="defaultButton">
  236. </CENTER>
  237.  
  238. <INPUT TYPE="hidden" NAME="in_button" VALUE="">
  239. <INPUT TYPE="hidden" NAME="in_sc_code" VALUE="YANGSC">
  240. <INPUT TYPE="hidden" NAME="in_owner_code" VALUE="YANG">
  241. <INPUT TYPE="hidden" NAME="in_wh_entity" VALUE="DEMO">
  242. <INPUT TYPE="hidden" NAME="in_rma_no" VALUE="">
  243. <INPUT TYPE="hidden" NAME="in_menu_id" VALUE="B5DE63798DE48B52">
  244. </FORM></td></tr>
  245. </BODY>
  246. </HTML>
  247.  
  248.  
Thanks in advance
Feb 8 '07 #1
8 5598
dmjpro
2,476 Top Contributor
i am working on ie..
because our project is ie specific...
i do in ie =============== ==
u r trying to get the row no on clicking the mouse on a particular cell.......
event.srcElemen t.parentElement .rowIndex
did u try it....
plz send me ur reply...
i am online!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!
Feb 8 '07 #2
yangtono
10 New Member
i am working on ie..
because our project is ie specific...
i do in ie =============== ==
u r trying to get the row no on clicking the mouse on a particular cell.......
event.srcElemen t.parentElement .rowIndex
did u try it....
plz send me ur reply...
i am online!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!
Hi,

Thanks for your reply. What I meant is when I click the "Add Row" 2 times, the page shows me 2 rows. But when I click on the first row of "Browse" button, I got the data from second row (or last row). I need to find out how to get the correct row no or should I say which "Browse" button I clicked.

The program I'm working on will list all the products from the "Stock Location". If first row stock location is "1-1-1-1", I expect to get the data when I click on first "Browse" button.
Feb 8 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
On the browse button onclick, instead of passing the count, pass the rowno instead.
Feb 8 '07 #4
dmjpro
2,476 Top Contributor
i think u have a header portion of the table...
then do subtract one from the orginal returned rowIndex..
plz send me u response
best of luck
Feb 8 '07 #5
yangtono
10 New Member
i think u have a header portion of the table...
then do subtract one from the orginal returned rowIndex..
plz send me u response
best of luck
Hi,

How do I get the rowIndex? I make use of "count2" to keep track of the row no, but instead it return me the total row.
Feb 9 '07 #6
acoder
16,027 Recognized Expert Moderator MVP
You can use the rowIndex property of the tr object or you can use parentNode to get its parent.

See the following links:
http://www.w3schools.com/htmldom/dom_obj_tablerow.asp
http://developer.mozilla.org/en/docs...DOM_Interfaces
Feb 9 '07 #7
yangtono
10 New Member
You can use the rowIndex property of the tr object or you can use parentNode to get its parent.

See the following links:
http://www.w3schools.com/htmldom/dom_obj_tablerow.asp
http://developer.mozilla.org/en/docs...DOM_Interfaces
Hi,

Thanks for yur suggestion, but I've seen these website. But I don't quite understand the term rowIndex property. How do I use these in javascript?
Feb 12 '07 #8
acoder
16,027 Recognized Expert Moderator MVP
See this example.

Once you have the table row object (give these an id), just use the rowIndex attribute:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById(tablerowid).rowIndex
where "tablerowid " is the id to your tr element.
Feb 12 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
25797
by: Don Grover | last post by:
I have a HTML table created using ASP as a web page. ie. HEADING1 HEADING2 HEADING3 etc... data 1 data2 data3 etc and so on How can I toggle hide / show the columns individually, anyone ever needed to do this and have any suggestions.
2
7744
by: Stephen Weatherly | last post by:
Could anyone please help me with a problem I am having with my table widths??? If I have 2 images within a td tag, but using CSS relative positioning I position one over the top of the second (I am placing a transparent gif over the top of a normal gif) then the width of my table is large enough to accommodate both images side by side My...
4
26204
by: N. Demos | last post by:
The following code renders as intended in IE (A TABLE, with cells of fixed width and height, inside of a DIV with fixed width and height and overflow set to hidden.) In Firefox, the table cells assume a narrower with than specified. If I comment out the width for the DIV, then the cells render with the correct width and height. Why is this...
6
1779
by: Christopher Benson-Manica | last post by:
I have some markup like the following: <form> <table> <script> <!-- Write the table markup //--> </script> </table> <form>
5
3111
by: Patient Guy | last post by:
In my reading of the Strict and Transitional DTD for HTML 4.0, the table row (TR) elements are contained within table section elements: THEAD, TFOOT, and TBODY. The table section elements are the defined contents of the TABLE element. The TR element is not defined as an "immediate" or "direct" contained element of TABLE. Given that
11
3565
by: Norman L. DeForest | last post by:
Am I misunderstanding the CSS specifications or is Firefox (version 1.0.6) (and Opera) doing the wrong thing? It appears that Firefox 1.0.6 includes the border in width calculations for tables but not in height calculations. Oh, and Opera version 8.02 does the same thing. |<-->| |<-->| <------ border |<------------>| ...
5
1868
by: mm nn | last post by:
Hi, I want to create a table like this: ID Autonum Datefld Date Cat Text Itm Text tCount Number
16
3475
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record in a hidden field) I wish the user to be able to edit the data in the table, so I have extracted the records into hiddenfield, textareas, dropdown...
2
3887
by: banderson | last post by:
Hello, I have a data entry form for a table with information about buildings and am having a problem making a combo box do what I want. I would like to make the combo box show a list of unique bldg mgmt company names and then to open a building management company form to show all records with this name, so the user can find the correct branch...
2
1225
by: Harshpandya | last post by:
Here is my code for look up table - where i am planning to built 10 colums and 8 rows and put array values in the table boxes. Problem is - it is only printing the last array valules instead of all var maxRow = 10; var maxCol = 8; var height1 = 480; var width1 = 640; function CenteringError(Xe, Ye){ var table = new Array ( (, ...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.