/    Sign up×
Community /Pin to ProfileBookmark

Table with DOM/Javascript

what’s wrong with this? The table is not displaying?

[CODE]<head>
<title>Le Tableau SmartLinks en DOM</title>
<script>
function start() {
// récupère une référence vers l’élément body
var mybody = document.getElementsByTagName(“body”)[0];

// création des éléments <table> et <tbody>
smartlinkstable = document.createElement(“table”);
smartlinksTbody = document.createElement(“tbody”);

// création des cellules
for(var j = 0; j < 2; j++) {
// création d’un élément <tr>
ligneSmartLinks = document.createElement(“tr”);

// for(var i = 0; i < 2; i++)

// création d’un élément <td>
celluleSource = document.createElement(“td”);
// création d’un nœud texte
contenuSource = document.createTextNode(“la colonne des Sources);
// ajoute le nœud texte créé à la cellule <td>
celluleSource.appendChild(contenuSource );
// ajoute la cellule <td> à la ligne <tr>
ligneSmartLinks.appendChild(celluleSource);
}
// ajoute la ligne <tr> à l’élément <tbody>
smartlinksBody.appendChild(ligneSmartLinks);
}

// ajoute <tbody> à l’élément <table>
smartlinksTable.appendChild(smartlinksTbody);
// ajoute <table> à l’élément <body>
mybody.appendChild(smartlinksTable);
// définit l’attribut border de mytable à 2;
smartlinksTable.setAttribute(“border”, “2”);
}
</script>
</head>
<body onload=”start()”>
</body>
</html>[/CODE]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@DetectAug 02.2007 — smartlinksBody is missing a T

smartlinksTable is defined as smartlinkstable (js vars are case sensitive)

Use your javascript error console!
Copy linkTweet thisAlerts:
@steveaAug 02.2007 — I'm thinking Firebug should come preloaded with FF, and that FF should come preloaded on every OS, and FF should remove IE everytime it is loaded. That would save a lot of time.
Copy linkTweet thisAlerts:
@kreelinauthorAug 02.2007 — smartlinksBody is missing a T

smartlinksTable is defined as smartlinkstable (js vars are case sensitive)

Use your javascript error console![/QUOTE]

thks
Copy linkTweet thisAlerts:
@kreelinauthorAug 03.2007 — [CODE]<html>
<head>
<title>Code de démonstration - Explorer un tableau HTML avec des interfaces DOM et JavaScript</title>
<script>
// Example ObjetSmartLink en json
var SmartlinkJson = {"id_source":"7315f47dba65515fca60c851d7065bc6","url_source":"http://news.yahoo.com/s/afp/20060822/od_afp/chinacateringcultureoffbeat_060822074830","title_source":"Jail-theme teahouse becomes prisoner of own success in China - Yahoo! News","smartlinks_infos":[{"id_dest":"75effc69e8c68b389c65c67119463312","score":"126","deleted":"0","date":"1164279208","zone_cible":"151","manually_added":"0","url_dest":"http://news.yahoo.com/s/afp/20060825/od_afp/malaysiahealthtoilets_060825160532","title_dest":"Malaysia calls for "toilet revolution" - Yahoo! News"}]};
//var SmartlinkJson = <?= $jsonstring ?>
//fonction de construction de SmartLinks

var SmartLink = eval(SmartlinkJson);
alert(SmartLink.id_source);


//fonction d'affichage de SmartLinks
function DisplaySmartLinks (SmartLink) {

//récupere une référence vers l'élément SmartLinks
var zone_affichage = document.getElementById("SmartLink")

//var TableCible=new Array('Titre_Cible"', 'Date_cible');
var Props=new Array('id_source', 'url_source', 'title_source', 'smartlinks_info');
// récupère une référence vers l'élément body
// var mybody = document.getElementsByTagName("body")[0];

// création des éléments <table> et <tbody>
smartlinksTable = document.createElement("table");
smartlinksTbody = document.createElement("tbody");
//for (p=0;p<Props.length;p++){
// création des cellules
for(var j = 0; j < 2; j++) {
// création d'un élément <tr>
smartlinksLine = document.createElement("tr");

// création du premier élément <td> de la ligne SmartLinks
smartlinksCell1 = document.createElement("td");
for (k=0; k<2; k++) {

smartlinksCell1.innerHTML += 'cellule source<br />';
//smartlinksCell1.innerHTML +=SmartLink[Props[p]]
}
// ajoute la premiere cellule <td> à la ligne <tr>
smartlinksLine.appendChild(smartlinksCell1);

// création du second élément <td> de la ligne smartlinks
smartlinksCell2 = document.createElement("td");
for (l=0; l<6; l++) {
smartlinksCell2.innerHTML += 'liens cibles<br />';
}
// ajoute la seconde cellule <td> à la ligne <tr>
smartlinksLine.appendChild(smartlinksCell2);

// ajoute la ligne <tr> à l'élément <tbody>
smartlinksTbody.appendChild(smartlinksLine);
// }
}
// ajoute <tbody> à l'élément <table>
smartlinksTable.appendChild(smartlinksTbody);
// ajoute <table> à l'élément <body>
zone_affichage.appendChild(smartlinksTable);
// définit l'attribut border de mytable à 2
smartlinksTable.setAttribute("border", "1");
}
</script>
</head>
<body onload="DisplaySmartLinks()">
<div id="Smartlink">
le test d'affichage
</div>
</body>
</html>[/CODE]
×

Success!

Help @kreelin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...