Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old December 1st, 2004, 05:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Your code with the above three changes applied:
Code:
<html>
    <head>
        <title></title>
        <script>

            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");

                    oTable.border=0;
                    oTable.cellSpacing=1;
                    oTable.cellPadding=1;

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

                    // TR

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


                    // 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 + "'/>";
                            oTR.appendChild(oTD1);


                        }


                    }

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

            }            


      </script>

    </head>
    <body>
        <form action="" name="frmCreate" ID="frmCreate">
            <table id="tblCreate">
                <tr>
                    <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>

                </tr>
                <tr>
                    <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>
                </tr>
            </table>

            <div id="tblDiv">

            </div>

        </form>
    </body>
</html>
Reply With Quote
  #12 (permalink)  
Old December 2nd, 2004, 07:15 AM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

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??

Also:

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.

Cheers,

Claudio




Reply With Quote
  #13 (permalink)  
Old June 27th, 2005, 10:36 AM
Authorized User
 
Join Date: Sep 2004
Location: , , USA.
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:37 AM.


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