Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table Trouble 1

Status
Not open for further replies.

TommyB44

Technical User
Jun 16, 2005
76
GB
Hi, All

I've tested this code on firefox and IE.

For some reason the table in this code doesn't work,
the code it's self works fine and if i change the td's
for font's then it displays the way it should. The answer
might be simple, but if it is i can't see it.

The Code ..

Code:
<body onload='Getlist();' leftmargin=0 topmargin=0>
<script>
var s="#2111~bob~22~Spain#3221~paul~26~USA#5476~sam~45~UK";
function Getlist() {
    var users = s.split("#");
    for(i=1; i<users.length; i++){
        user = users[i].split("~");
        users[i]={
            userID: user[0],
            userName: user[1],
            age: user[2],
            location: user[3]
        }
    }
    
    var list = document.getElementById("list");
    list.innerHTML = "<table width=100%>";
    
    for(i=1; i<users.length; i++){
        list.innerHTML += "<tr><span id="+users[i].userID+"><td style='width:20%;background:black;color:white'>"
                                +users[i].userName+"</td><td style='text-align:center;width:10%;background:black;color:red'>" 
                                + users[i].age +"</td><td style='width:70%;background:black;color:red'>"
                                + users[i].location+"</td></tr>";
    }
    
    list.innerHTML += "</table>";
}
</script>

HTML CODE
<SPAN id="list">
</SPAN><br>
HTML CODE

Any help would be great, Thanks for reading.
 
For the second part of the function, do it like this.
[tt]
var list = document.getElementById("list");
var t = "<table width=100%>";

for(i=1; i<users.length; i++){
t += "<tr><span id="+users.userID+"><td style='width:20%;background:black;color:white'>"
+users.userName+"</td><td style='text-align:center;width:10%;background:black;color:red'>"
+ users.age +"</td><td style='width:70%;background:black;color:red'>"
+ users.location+"</td></tr>";
}

t += "</table>";
list.innerHTML = t;
[/tt]
As a side note, why you name variable in such a way of testing the naming resolution of browsers? Like list, without the getElementById line, list.innerHTML is something of some meaning in ie. Try avoid such kind of stretching---just an opinion.
 
Thanks, tsuji

i'm still new to Javascript, but thanks for pointing that out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top