Set value of text area and have it register a change
<p>I have a text area:</p>

<pre><code>&lt;input id="startdate" name="startdate" type="text" value="" style="width:23%"&gt;
</code></pre>

<p>that listens to on('change')`</p>

<pre><code>$('#startdate').on('change', function () {
  var $formelem = $(this);
  // DO SOME WORK
  ... 
});
</code></pre>

<p>and the code to change the value of the text area:</p>

<pre><code>var keyval = location.search.replace('?', '').charAt(0);
  var filterDates;
  var clicked = [];

  function persistence(keyval) {
    function template(keyval, filterDates) {
      for ( i=0 ; i &lt; keyval.length ; i++ ) {
        $('#'+keyval[i]).click();
      };
      if (filterDates) {
        return $('#startdate').val(filterDates);
      };
    };
    if (typeof parseInt(keyval[0]) === 'number' &amp;&amp; keyval[0] % 1 == 0) {
      switch(keyval[0])
        {
        case '1': 
          keyval = ['.', '..', '...' ];
          filterDates = "2006-04";
          template(keyval, filterDates);
          break;
        case '2': 
          keyval = ['.', '..', '...' ]; 
          break;
        default:
          template(keyval);
        };
    } else {
      template(keyval);
    }
  };
</code></pre>

<p>When the page loads, if the url contains a <code>1</code>, then I want to change the value of the textarea to <code>2006-04</code> AND have it register a change, so that the change function occurs.   Currently the text is getting updated, but the function is not running.   I think it might have something to do with the page not being loaded, so I placed it in the document.ready(), and it is still not working.   Anything else I am missing?  The <a href="http://api.jquery.com/val/" rel="nofollow">API</a> doesn't mention anything about having to attach an event handler to it, so I thought that the on('change') would do the trick.....</p>

<p>Also, if I manually change it, the function does do the work it is supposed to do, so its not the code in the function.   Also does the fact that I dynamically set the initial value elsewhere have anything to do with it?</p>

<pre><code>$(document).ready(function () {
    blinks(1);
    persistence(keyval);
});
</code></pre>

<p>and</p>

<pre><code>//place the first value of start[] in the startdate box
$('#startdate').val(start[0]);
</code></pre>
