title: Ensure JavaScript/jQuery function always runs on page load
body: <p>I tried all of the alternative examples I could find and couldn't get this to work. I may have it implemented incorrectly. Any help is greatly appreciated.</p>
  
  <p><strong>My issue:</strong></p>
  
  <p>I have a function that is meant to slideDown an alert if specific values in the are in the textarea. </p>
  
  <p>This function works if the user types in the textarea, but the values are usually passed in from another page. How can I make it run without requiring that they interact with the text area?</p>
  
  <p>Here's my example on JSFiddle: <a href="https://jsfiddle.net/zrdunlap/cjo3u79e/" rel="nofollow">Example</a></p>
  
  <p>And here is the HTML/JS code for easy reading:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;!doctype html&gt;
   &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Alert Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class="controls"&gt;
          &lt;textarea name="q" class="span12"  id="textarea" rows="5"&gt;one:&lt;/textarea&gt;
      &lt;/div&gt;
      Test alert:
      &lt;div class="alert alert-error" id="alert" name="alert" style="display: none;"&gt;
          This is a test alert.
          &lt;a href="#" class="close" data-dismiss="alert"&gt;&amp;times;&lt;/a&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
  &lt;script src="textAreaReader.js"&gt;&lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>JS:</strong></p>
  
  <pre><code>$(document).ready(function(){
  $('#textarea').on('change keyup paste', function() {
  var lines = $('#textarea').val();
  var fields = ["one", "two", "three"];
  var leng;
  for (var i=0; i &lt; fields.length; i++) {
    if (lines.indexOf(fields[i] + ':') !== -1){
      leng = 1;
    }
  }
  if (leng == 1){
      $("#alert").slideDown("fast"); //Slide Down Effect
    }else{
       $("#alert").slideUp("fast");  //Slide Up Effect  
    }
  });
  });
  </code></pre>