ACE Editor reporting Javascript scoping errors incorrectly

javascript

#1

Please look at the following two successive Javascript blocks in a single file. I am calling the write2doc function defined in the first script block in the code in the second block.The ACE editor is flagging this as a syntax error (lines flagged with yellow ! marks) because it looks like it cannot connect the rwo script blocks during scoping analysis. The program runs fine but showing these syntax errors incorrectly is bothersome in my view. If any one has an insight into fixing this problem, please let me know. I have not enabled any particular JS library for the ACE editor and left the defaults. – Raj

  <script type="text/javascript">
    function write2doc(str) {
      var importDoc = document.currentScript.ownerDocument;
      var warning_div = importDoc.getElementById("warning");
	    var div = importDoc.createElement("div");
	    div.innerHTML = str;
	    warning_div.appendChild(div);
    }
  </script>
  
  <script type="text/javascript">
    write2doc("Hello 1<br>");
    write2doc("Hello 2<br>");
  </script>


<div id="warning">
  <style scoped>
    h3 {
      color: red;
    }
  </style>
  <h3>Warning!</h3>
  <script type="text/javascript">
    write2doc("Hello 3<br>");
  </script>
  <p>This page is under construction</p>
</div>

#2

Sorry my sample code did not go through. Here it is:


#3

How do I add Javascript code to a post?