Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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 March 27th, 2006, 02:30 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default createElement Tables... grrr

Hi,

I'm trying to add a row to a table, with cells and values.. but for some reason I'm unable to do so... Any help would be super...

I have this table, which is the 2nd one in the page...
<table>
    <tr>
        <td>Hello</td>
        <td>World</td>
    </tr>
</table>

And this is how I'm trying to do it...

var tables = document.getElementsByTagName("table");
var table = tables.item(1);
var nRow = document.createElement("tr");
table.appendChild(nRow);
var rows = table.getElementsByTagName("tr");
var row = rows.item(1);

var nData = document.createElement("td");
var nText = document.createTextNode(tempArr[1]);
nData.appendChild(nText);
row.appendChild(nData);

var nText = document.createTextNode(tempArr[2]);
nData.appendChild(nText);
row.appendChild(nData);

Now I've also tried doing it this way:

var nRow = document.createElement("tr");
var nData = document.createElement("td");
var nText = document.createTextNode(tempArr[1]);
nData.appendChild(nText);
nRow.appendChild(nData);
psqtFrame.document.getElementById('psqtTable').app endChild(nRow);

And nothing happens.. I only see Hello World... Any help would be great.

Thank you.

 
Old March 28th, 2006, 03:14 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii darkhalf!!

plz try this code

<script>
 var i=0
function clickme()
{
var mytable = document.getElementById("psqtTable")
 i++
            var row = mytable.insertRow(-1);

             // var row = mytable.insertRow(1); Also check with line

        mycurrent_cell=document.createElement("TD");

         filex = document.createElement('input');
          filex.setAttribute('type','file');

         mycurrent_cell.appendChild(filex)
         mycurrent_cell.appendChild(document.createTextNode ("Element"+i))
         mycurrent_cell.colSpan="2"
         row.appendChild(mycurrent_cell)
}


</script>
<table id="psqtTable" border=1 bgcolor="#FFFF00">
    <tr>
        <td>Hello</td>
        <td>World</td>
    </tr>
</table>
<input type=button onclick="clickme()" value=cl>


also read the useful link about tbody and appendchild method

 sad69 comment on
http://www.codingforums.com/archive/...p?t-35180.html


Cheers :)

vinod
 
Old March 28th, 2006, 03:22 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Useful links

http://www.codecomments.com/archive2...-9-594413.html

Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
creating tables within tables in access??? carswelljr Access 3 August 23rd, 2006 01:21 PM
Fixed tables and/or fixed bkgrnd in tables slg111875 Dreamweaver (all versions) 1 June 22nd, 2006 02:31 PM
tables gingar HTML Code Clinic 4 March 25th, 2005 05:58 AM
.onchange Event Handling Help GRRR! rolandatem Javascript 2 November 12th, 2004 04:42 PM
regarding tables spraveens Dreamweaver (all versions) 1 September 24th, 2003 07:21 AM





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