|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
So close! but no cigar - script to find last field in each row
Please help! I'm sure this is nearly there! The alert should output the contents of an array, which should be the value of the last text field in each row of a dynamic table. There must be an easier way to do this.
Here's the test page, Please don't laugh, it is a right dogs dinner I'm sure! NB:I put the script after the table so the table ID is ready. Thanks, Mark <html> <head></head> <body> <input name="Submit" type="submit" onClick="getValue()"; value="value of last field in each row"> <table width="48%" border="0" id="inventory"> <tr bgcolor="#00CC00"> <td width="13%">row 1</td> <td width="10%"> <input name="textfield" type="text" value="qty" size="5"></td> <td width="20%">$40.00 </td> <td width="57%"> <input name="textfield3" type="text" value="0.00" size="30"> </td> </tr> <tr> <td>row 2</td> <td><input name="textfield4" type="text" value="qty" size="5"></td> <td>$30.00</td> <td><input name="textfield6" type="text" value="0.00" size="30"></td> </tr> </table> <script language="JavaScript1.2" type="text/javascript"> <!-- var j=0; var arrayIncrement=0; var totalsArray=new Array(); var oTxt = new Array(); function getValue(){ if(document.getElementById) { var table = document.getElementById('table1'), rows; if(table && (rows = table.rows)) { // Add the listener to each row in the table. for(var i = 0;i<rows.length;++i) { //rows[i].onclick = showRowNum; //var oInp = thisrow. var oInp = this.getElementsByTagName('input'); for(x=0;x<oInp.length;i++){ if(oInp[x].type=='text'){ oTxt[j]=oInp[x]; var lastValue = oTxt[oTxt.length-1].value; j++; } totalsArray[arrayIncrement]=lastValue; arrayIncrement++; } } } } alert(totalsArray); } //--> </script> </body> </html> |
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > So close! but no cigar - script to find last field in each row |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|