title: How to use JavaScript to test a HTML div on content from an external database?
body: <p>I am trying to create a <code>html</code> letter. Each letter may or may not have conditions attached to it. Those conditions are stored in an <code>external sql database</code>.</p>
  
  <p>What if a <code>html div</code> contained database field such as:-</p>
  
  <pre><code>&lt;div id="Conditions"&gt;
      &lt;p&gt;dbfield(var)&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>What I need to do is test the resultant data rather than the actual <code>div</code> itself. See my last attempt:-</p>
  
  <pre><code>&lt;div id="Conditions"&gt;
      &lt;p&gt;dbfield(conditions)&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;div id="NoConditions"&gt;
      &lt;p&gt;No specific conditions apply&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;script type="text/javascript" language="javascript"&gt;
  &lt;!-- 
      if (document.getElementById("Conditions").innerHTML.length == 0){
          document.getElementById("Conditions").style.display = "none";
          document.getElementById("NoConditions").style.display = "inline";
      }
      else {
          document.getElementById("NoConditions").style.display = "inline";   
          document.getElementById("Conditions").style.display = "none";   
      }
  //--&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>In a nutshell, my dilemma is I want to test whether a result is returned from the database or not.</p>
  
  <p>I know this is a strange one but this is a <code>third party db</code> that I only have read access to inside a <code>web based interface</code> that creates the <code>html</code> form letters. However the prebuilt system has very limited functionality (can't use if's or then's) hence why I am using <code>javascript</code> to get around those limitations.</p>
  
  <p>I'm assuming it is doing something tricky with the type of data in the <code>div</code> as I have tried NULL tests, "" tests, <code>innerHTML</code> tests, using a <code>i++ counter</code>, <code>children</code> tests, <code>haschildnode()</code> tests. So far it has resisted all my interrogations.</p>
  
  <p>Any assistance would be appreciated.
  Thanks</p>