Wrox Programmer Forums
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 1st, 2004, 05:01 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax

Your code with the above three changes applied:

            function createTable(nRows, nCol)
                //alert(nRows + " " +  nCol);
                var oDiv;
                oDiv = document.getElementById("tblDiv");

                if(nRows > 0 && nCol >0)
                    // create table
                    var oTable = document.createElement("table");


                    // table body
                    var oTBody = document.createElement("tbody");

                    // TR

                    for (var i=0; i<nRows; i++)
                        var oTR = document.createElement("tr");

                    // TD    
                        for (var j = 0; j<nCol; j++)
                        // Unique id
                            var nCount = (i * nCol) + j    

                            var oTD1 = document.createElement("td");
                            oTD1.innerHTML = "<input type='text' id='" + nCount + "'/>";



//                oDiv.appendChild(oTable);
//                document.write(oDiv.outerHTML)    
                oDiv.innerHTML = oTable.outerHTML;
                frmCreate.txtRows.value = "";
                frmCreate.txtColumns.value = "";



        <form action="" name="frmCreate" ID="frmCreate">
            <table id="tblCreate">
                    <td>Number of Rows: <input type="text" id="txtRows" NAME="txtRows" value=""></td>
                    <td>Number of columns: <input type="text" id="txtColumns" NAME="txtColumns" value=""></td>

                    <td><input type="button" onclick="createTable(document.frmCreate.txtRows.value, document.frmCreate.txtColumns.value)" value="Create Table" id="button1" name="button1"></input>&nbsp;
                        <input type="button" onclick="alert(tblCreate.innerHTML)" value="INNERHTML" id="button2" name="button2"></input></td>

            <div id="tblDiv">


Old December 2nd, 2004, 07:15 AM
Friend of Wrox
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts

Hi Jonax,

I have really appreciated your help.

The way you did the unique id is really clever. Well done!!:)

There is one problem however, if the user by accident clicks the refresh button in the browser, the table will be cleared i.e. the table will disappear from the screen. Suppose the user had already typed some number there, he/she would loose everything. Is there a way to avoid that and maintain the state??


1 - How can I loop through both the first, second, etc rows and first, second, etc... columns? Suppose the columns represented the days of the week and the rows the name of the shop and the value entered the daily income. What I want to be able to do is to add all the values in the first column (Monday) to have a total for Monday. Then add the values of only second column to have a total for Tuesday.

Similarly, I need to be able to add the values in the first row for a particular shop then the values of the second row (Monday + Tuesday + Wednesday + ....) for the other shop and so on.

Finally, I need to be able to produce an average of sales based on days of week (each column separately) and per shop (each row separately).

I would really appreciate if someone could help with that.



Old June 27th, 2005, 10:36 AM
Authorized User
Join Date: Sep 2004
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts

maybe you don't need this anymore or probably you have to use Javascript and nothing else.

But I am using Microsoft's Office Web Components (OWC), which provides spreadsheet, pivot table, chart, and a data source control. You can read about it. No much code is needed to do that.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Workbook,Copy Sheet,Move Sheet, Close/Save ptrussell2009 Excel VBA 0 June 13th, 2008 02:28 PM
format report like spread sheet michael193nj Access 0 March 19th, 2008 05:17 PM
How to use Spread in VB anne1985 Beginning VB 6 2 October 3rd, 2006 07:30 PM
Archiving excel spread sheet in zipped form Hudson40 Excel VBA 0 January 5th, 2005 12:33 PM
save Excel spread-sheet to SQL Server ybao Classic ASP Databases 1 July 12th, 2004 03:02 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.