dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: Javascript code does nothing

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Unhappy Javascript code does nothing

    Hi all,
    i started a new project where you can see your daily timetable. I think the HTML
    part is correct but the something is wrong with the javascript part.
    Here is the Code:

    HTML Code:
    <script type="Text/javascript" >
    document.getElementById("days").firstChild.data =  "Montag";
    
    document.getElementById("erste").firstChild.data =  "Mathe";
    
    document.getElementById("zweite").firstChild.data =  "Geschichte";
    
    document.getElementById("dritte").firstChild.data =  "Biologie";
    
    document.getElementById("vierte").firstChild.data =  "Wirtschaft";
    
    document.getElementById("fünfte").firstChild.data =  "Englisch";
    
    document.getElementById("sechste").firstChild.data =  "Religion";
    
    document.getElementById("siebte").firstChild.data =  "Computer AG";
    
    document.getElementById("achte").firstChild.data =  "Computer AG";
    
    </script>
    
    
    
    
    </head>
    
    <body>
    
    
    
    <center>
    <table width="100" border="1">
      <tr>
        <th scope="col" id="days">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="erste">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="zweite">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="dritte">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="vierte">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="fünfte">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="sechste">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="siebte">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="achte">&nbsp;</th>
      </tr>
    </table>
    </center>
    Some classes and ids are in german because im from germany

  2. #2
    Join Date
    Feb 2012
    Posts
    218
    Move the script at the end of the file. This is because when you call the js scrip, DOM is not ready yet and you have no element with id "erste" or "zweite".
    HTML Code:
    </head>
    
    <body>
    
    
    
    <center>
    <table width="100" border="1">
      <tr>
        <th scope="col" id="days">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="erste">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="zweite">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="dritte">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="vierte">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="f&#252;nfte">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="sechste">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="siebte">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row" id="achte">&nbsp;</th>
      </tr>
    </table>
    </center>
    
    
    <script type="Text/javascript" >
    document.getElementById("days").firstChild.data =  "Montag";
    
    document.getElementById("erste").firstChild.data =  "Mathe";
    
    document.getElementById("zweite").firstChild.data =  "Geschichte";
    
    document.getElementById("dritte").firstChild.data =  "Biologie";
    
    document.getElementById("vierte").firstChild.data =  "Wirtschaft";
    
    document.getElementById("f&#252;nfte").firstChild.data =  "Englisch";
    
    document.getElementById("sechste").firstChild.data =  "Religion";
    
    document.getElementById("siebte").firstChild.data =  "Computer AG";
    
    document.getElementById("achte").firstChild.data =  "Computer AG";
    
    </script>
    Also, instead of
    document.getElementById("achte").firstChild.data = "Computer AG";
    you can use
    document.getElementById("achte").innerHTML = "Computer AG";

  3. #3
    Join Date
    Feb 2012
    Posts
    2
    Ohh i thought about that it was this kind of mistake.
    Thank you a lot

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles