Home arrow HTML arrow Page 5 - 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 - Add a Row
(Page 5 of 5 )

You add (insert) a row using a row index. If you add (insert) a row with index 3, the row which had the index 3 will now have the index 4. When you add a row, it pushes the row which was at its position, and the rows below that one, one step downward. The following statement would add a row with the index value of i.

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


Notice the method “insertRow(i)” at the end. When you add a row, the row is empty, that is, it does not have a cell. You then have to add (insert) cells in the row. The following statement will add (insert) a cell in the row whose index value is i, and at a position where the cell (column) index is j.


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


Notice the method “insertCell(j)at the end. To add more than one cell, you need a loop.


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


<br /><br />

<button type="button" onclick="addRow(5,6)">Add Row</button>


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


function addRow(rowNo,noColms)

{

document.getElementById('Recordset1').insertRow(rowNo);


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

{

document.getElementById('Recordset1').rows[rowNo].insertCell(j);

}

}


This function takes, as arguments, the row index and the number of cells (noColms -- for number of columns). It produces the row and then the “for” loop produces the cells.


Conclusion

Any good container can be used as a recordset. The HTML table element can be used as a recordset in a web page. With the value of “none” for the CSS display property, you do not see the recordset. With the value of “block” for the CSS display property, you see the recordset. The DOM allows us to use the HTML table as a recordset.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials