2

hello i am currently busy trying to get a .js file into a table now i have written a for loop but it doesnt show i will show u down below my code

The Html/javascript Code

<!DOCTYPE html>
<html lang="nl-NL">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<meta name="description" content="Dit is de website van Gerard Van De Weijer Hobbyist en Vader van 3">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/website-papa.css">
<meta name="robots" content="index, nofollow">
<meta name="author" content="Gerard Van De Weijer">
<meta name="web-author" content="Pieter Van De Weijer">
<link rel="canonical" href="http://website-gerard.com">
<meta charset="UTF-8">
<script src="sources/tabledata.js"></script>
  <script>
    function readJSON(persons)
    {
     var output = '';
     for (var i = 0; i < persons.length; i++)
     {
     output += '<td>'+persons[i].firstname+'</td>';
     }
     document.getElementsByClassName('firstname').innerHTML = output;
    }
  </script>
<title> Tables</title>
</head>
<body>
<!--dit is is een container-->
 <div id="container">
  <header>
  <h1>t02m91</h1>
  <div id="facebook">
  <a href="https://www.facebook.com/gerard.vandeweijer.5"><img src="images/facebook.png"></a>

  </div>
  </header>
  <nav>
  <ul>
   <li class="menuli"><a href="index.html">Home</a></li>
   <li class="menuli"><a href="Anchors.html">Anchors</a></li>
   <li class="current"><a href="Tables.html">Tables</a></li>
   <li class="menuli"><a href="Iframes.html">Iframes</a></li>
   <li class="menuli"><a href="html5.html">HTML5</a></li>
   <li class="menuli"><a href="contact.html">Contact</a></li>
   <li class="menuli">Opdrachten
   <ul>
   <!-- ik kon er geen spatie in krijgen dus ik heb het zo gefixt ik leg dit uit in de les-->
   &nbsp;<li><a href="opdracht3t02m03.html">Borders</a></li>
   <li><a href="opdracht3t02m04.html">Classes</a></li>
   <li><a href="opdracht1t02m06.html">Floats</a></li>
   <li><a href="opdracht3t02m06.html">Z-index</a></li>
   </ul>
   </li>
   </ul>
  </ul>
  </nav>
  <main>
  <h1>Tables</h1>
  <table>
   <tr>
    <th>Voornaam</th>
    <th>Achternaam</th> 
    <th>Leeftijd</th>
    <th>Woonplaats</th>
   </tr>
   <tr>
    <div class="firstname"><script>readJSON(persons);</script> </div>
    <td class="firstname"></td> 
    <td class="firstname"></td>
    <td class="firstname"></td>
   </tr>
   <tr>
    <td></td>
    <td></td> 
    <td></td>
    <td></td>
   </tr>
   <tr>
    <td></td>
    <td></td> 
    <td></td>
    <td></td>
   </tr>
   <tr>
    <td></td>
    <td></td> 
    <td></td>
    <td></td>
   </tr>
  </table>
  </main>
  <footer>
   <span> Gerard Van De Weijer 2017™</span>
  </footer>
 </div>
</body>
</html>

.js file

var persons = [
 {"firstname":"Nel", "lastname":"De Beer", "age":9, "location":"Weert"},
 {"firstname":"Bob", "lastname":"Janssen", "age":33, "location":"Eindhoven"},
 {"firstname":"Beatrix", "lastname":"Peperkamp", "age":76, "location":"Nijmegen"}
];

i hope someone can help me i think im forgetting to declare that it has to be put in that table or maybe make that function into a var i hope you guys can clear this up thanks in advance

with regards GPM

  • 1
    `getElementsByClassName` returns a list of elements. Because of that you set the property `innerHTML` on that list and not on a DOMElement. – t.niese May 22 '18 at 15:19
  • Given that this post contains all-lower-case writing, txtspk and is rather too chatty for the technical writing we prefer here, it is somewhat surprising it has attracted two upvotes. If you have friends or colleagues who are being "helpful" by upvoting your post, please ask them to desist - it is not a good long-term strategy for posting on Stack Overflow. It is detected fairly reliably by moderators, and can lead to a suspension or ban. – halfer May 22 '18 at 20:40
  • Hello halfer i have no idea what u are on about i assure u i came here for help that is all also i apoligze for lack of grammar and , . i am really bad at them – Guitarpunkmasta May 23 '18 at 03:35

0 Answers0