word counter Javascript function call
<p>Wanted to have a word counter next to a input textbox on the website</p>

<p>Got it working to show the count when the user click or modify the text but I wanted to load up straight away when the page finish loading.</p>

<pre><code>$(document).ready(function() {

  $("#product_name").change(displayText).keyup(displayText);

function displayText(){
      $("em#counter").text($(this).val().length +' chars'); 
}
});
</code></pre>

<p>So I tried this the code below but couldn't get it working and don't know why.</p>

<pre><code>$(document).ready(function() {

    if($("#product_name").length){
           displayText();
    }
  $("#product_name").change(displayText).keyup(displayText);

function displayText(){
      $("em#counter").text($(this).val().length +' chars'); 
}
});
</code></pre>

<p>Thanks so much.</p>
