Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collecting values in 2 Table columns 1

Status
Not open for further replies.

Isadore

Technical User
Feb 3, 2002
2,167
US
I have a table generated by asp.net that issues ID's such as: "dgOrders__ctl2_txtqty" for one column of textboxes (user input). What I am trying to do is to collect two columns within the table to pass as Querystring variables.

The table is manipulated on the Client side by either changing the value in the textbox and/or deleting one or more of the rows. The problem is I cannot use the ID to collect the data in the two columns because the chronological order of the ID's change after a deletion event. One of the columns is easily collected by using the innerText approach:
Code:
...
 var invtable = document.getElementById('dgOrders');
  for (var i=0;i<invtable.rows.length-1;i++){
     var strpde = invtable.rows[i].cells[1].innerText;
...

Collecting the textbox values in rows.cells[5] by referring to its ID is hindered because of rows deleted by the Client.

Textbox names behave as follows:

dgOrders__ctl2_txtqty
dgOrders__ctl3_txtqty
dgOrders__ctl4_txtqty
dgOrders__ctl5_txtqty
dgOrders__ctl6_txtqty

..after Client deletion:

dgOrders__ctl2_txtqty
dgOrders__ctl4_txtqty
dgOrders__ctl6_txtqty

I have tried searching here for a simple routine to re-name the rows but no luck. Also, I have had problems trying to use the "getElementsbyID" approach because there are two input objects in each row (a button and the requisite textbox).

Appreciate any guidance here - thanks in advance..
 
This is how you walk through the table and collect the input type-text's value.
[tt]
var invtable=document.getElementById("dgOrders");
for (var i=0;i<invtable.rows.length;i++) {
for (var j=0;j<invtable.rows.cells.length;j++) {
var obj=invtable.rows.cells[j];
var celem=obj.getElementsByTagName("input");
for (var k=0;k<celem.length;k++) {
if (celem[k].type=="text") {
alert("row#: " + i + "\n" + "column#: " + j + "\n" + "input (text) value: " + celem[k].value + "\n" + "input (text) name: " + celem[k].name); //for instance
}
}
}
}
[/tt]
Notes:
[1] There is no such thing as "getElementsByID".
[2] innerText is ie-proprietary, not broadly supported.
 
tsuji: My mistake, it should have been "getElementsByTagName" - I had been working on this problem for so long I didn't even notice.

W.r.t. [2] should I simply change over to 'innerHTML'?

Thanks tsuji, you have been a great help.
 
Thanks, Isadore!

>W.r.t. [2] should I simply change over to 'innerHTML'?

Not really. In simple context where within the tr, there is only an input node. Then using innerHTML does give you a broader browser support and you sure can parse the value of of the input textbox by so doing. But those who do not even like innerHTML would still criticizing that by appealing to innerHTML, you surrender precision method of pin-pointing the target object and then taking appropriate action on it like retrieving the value. The script blog that I show is the reason behind that viewpoint as precise reference to the input control can be made and such reference, the value is then retrieved.

The main point is that getElementsByTagName is not privy to document object. In fact any htmldocument object type can use the method to get those references which are children of the parent element. The script blog use it one the cell object of index (i,j). And that is the meaning of the construction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top