title: How do you return data from javascript into a html form?
body: <p>I was wondering if anyone can help? What I am trying to do is retrieve the word count from  javascript code into a form and then pass it into php along with the rest of the form which will check that the word count is a certain length or else it won't be submitted.</p>
  
  <p>The javascript is as follows.</p>
  
  <pre><code>    counter = function() {
         var value = $('#msg').val();
  
         if (value.length == 0) {
            $('#wordCount').html(0);
            $('#totalChars').html(0);
            $('#charCount').html(0);
            $('#charCountNoSpace').html(0);
            return;
         }
  
         var regex = /\s+/gi;
         var wordCount = value.trim().replace(regex, ' ').split(' ').length;
         var totalChars = value.length;
         var charCount = value.trim().length;
         var charCountNoSpace = value.replace(regex, '').length;
  
         $('#wordCount').html(wordCount);
         $('#totalChars').html(totalChars);
         $('#charCount').html(charCount);
         $('#charCountNoSpace').html(charCountNoSpace);
     };
  
     $(document).ready(function() {
        $('#count').click(counter);
        $('#msg').change(counter);
        $('#msg').keydown(counter);
        $('#msg').keypress(counter);
        $('#msg').keyup(counter);
        $('#msg').blur(counter);
        $('#msg').focus(counter);
     });
  </code></pre>
  
  <p>My problem is returning wordCount into a hidden field in a form. I am not too good with javascript and am not sure how to modify this code to make it work. The rest I can figure out but am stuck here. Thank you for your help, it is greatly appreciated.</p>