Home arrow HTML arrow Page 4 - Using the HTML Table Element as a Recordset
HTML

Using the HTML Table Element as a Recordset


When you query a database, the result you receive is a recordset. The form in which your result can be presented is affected by the capabilities of the language you use. This can present a challenge for certain languages. This article presents one way to meet that challenge if you program for the web.

Author Info:
By: Chrysanthus Forcha
Rating: 4 stars4 stars4 stars4 stars4 stars / 7
July 21, 2008
TABLE OF CONTENTS:
  1. · Using the HTML Table Element as a Recordset
  2. · Minimum Requirements of a Read/Write Recordset
  3. · Our Illustrative Web Page
  4. · Editing Data
  5. · Add a Row

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using the HTML Table Element as a Recordset - Editing Data
(Page 4 of 5 )

The following code would return or set the text and/or code that is in the table cell in row i and column j.

document.getElementById('Recordset1').rows[i].cells[j].innerHTML

Note the innerHTML property of the Table Cell object in the statement. Also note that counting of rows or cells or columns begins from zero.

Now, add the following button (code) to the body element in the above file content.


<br /><br />

<button type="button" onclick="modifyRow(2)">Modify Row</button>


The above button will call the following function, which uses an array. Include this code in the JavaScript above.


arr1 = new Array(6)

arr1[0]="70";

arr1[1]="Wright";

arr1[2]="30";

arr1[3]="Sales";

arr1[4]="4";

arr1[5]="18045.50";


function modifyRow(rowNo)

{

for (j=0;j<6;j++)

{

document.getElementById('Recordset1').rows[2].cells[j].innerHTML = arr1[j];

}

}


The function takes the row number as argument. It replaces all the cell values of the row with the values of the array. If you want to edit only the content of one table cell, you do not need the “for” loop. You can now open the file in a browser and test the code.

Delete a Row

The following statement would delete the row whose index is given, from a table. The index and the position of the deleted row are taken up by the row below it.

document.getElementById('Recordset1').deleteRow(i)


Now, add the following button (code) to the body element in the above file content.


<br /><br />

<button type="button" onclick="deleteRow(3)">Delete Row</button>


The above button will call the following function. Include this code in the JavaScript above.


function deleteRow(rowNo)

{

document.getElementById('Recordset1').deleteRow(3)

}


The function takes the row number 3 as argument. It deletes the row. The row that had the index, namely 4, is now the row with the index 3. You can try the code.


blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials