getting style error for display with JS but works smoothly in jsfiddle

Viewed 88

I have the code below. My desired outcome is exactly how it is in jsfiddle: works perfectly! In my browser, I get these two errors that differentiate it:

code:

http://jsfiddle.net/pbvwjL94/1/

GET http://localhost/favicon.ico 404 (Not Found)

realjs.js:236 Uncaught TypeError: Cannot read property 'style' of null
    at showForm (realjs.js:236)
    at HTMLSelectElement.onchange (testwriting.php:57)

In my browser, the writing sections work perfectly and the reading section works when I choose science. However, the error still appears. The other sections just do not work.

I know it is a lot of code but I have been scouring the web for answers for so long and nobody has been able to help me.

I really need it guys

Thanks

As asked, here is my element with id f9

<div class="form-group" name="skill5" id="f9" style="display:none">
      <select class="form-control" name="skill5" id="readingsocialstudies" onchange="showForm()" data-required>
        <option value="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Select Your Skill-</option>
        <option value="Big Picture">Big Picture</option>
        <option value="Attention to Detail">Attention to Detail</option>
        <option value="Inference">Making Inferences</option>
        <option value="Function">Identifying Function</option>
        <option value="Vocabulary In Context">Vocabulary In Context</option>
        <option value="Analogy">Drawing Analogies</option>
        <option value="Author Technique">Author Technique</option>
        <option value="Evidence Support">Supporting with Evidence</option>
        <option value="Data Reasoning">Data Reasoning</option>
      </select>   
      <br style="line-height:10px;">
      <select class="form-control" name="passageid1" data-required>
        <option value="">&nbsp;&nbsp;&nbsp;-Select Your Passage ID-</option>
          <?php 
            $sql = mysqli_query($connect, "SELECT ID FROM excerptlist");
            while ($row = $sql->fetch_assoc()){
              $ID = $row['ID'];
              echo "<option value='".$ID."'>" . $ID . "</option>";
            }
          ?>
      </select>  
    </div>


1 Answers

The error message points you to line 236

document.getElementById("f9").style.display = "none";

Looking at your html, there's no element with id f9. This means that document.getElementById("f9") will return null, and it's not possible to get the property .style on that.

If you add the correct element, I think your code will work fine

Related