0

How do I get this javascript to populate the textarea?

<body onload="form1.submit();"><div align="center">Loading...</div>
<script type="text/javascript" src="<%= g_page_site_actual %>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<%= g_page_site_actual %>/js/jquery.wordstats.js"></script> <!-- core code -->
<script type="text/javascript" src="<%= g_page_site_actual %>/js/jquery.wordstats.en.js"></script> <!-- English stop words -->
<script type="text/javascript">
        $(function() {
            var count = 20;
            $.extend($.wordStats.stopWords, {'retrieved': true, '2007': true});
            $.wordStats.computeTopWords(count);
            var msgcounttext1 = '<%=completehtml%>'
            for(var i = 0, j = $.wordStats.topWords.length; i < j && i <= count; i++) {
               msg += $.wordStats.topWords[i].substring(1) + ', ';
            }
            {
            document.form1.textarea.value = document.write(msgcounttext);
            }
            $.wordStats.clear();
        });
        </script>
<div id="content" class="hidden"><%=completehtml%>
    <form id="form1" name="form1" method="post" action="test.asp">
        <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>
    </form>
  </div>
</body>

Thanks

2
  • Does this javascript throw an exception. At a quick glance I would suggest removing the document.write(... Commented Jan 21, 2011 at 20:25
  • i.e.document.form1.textarea.value = msgcounttext; Commented Jan 21, 2011 at 20:26

4 Answers 4

1

try

document.form1.textarea.value= msgcounttext;
Sign up to request clarification or add additional context in comments.

Comments

1

Sample of a JQuery function to do that...

$('a').click(function()  
{ 
   $('#textarea').val('Insert this into the Text Area'); 
   //this puts the 'Insert this..' into the text area with the id 'textarea'
})

Comments

0

Besides not having a variable named msgcounttext, get rid of the document.write call.

Comments

0

The document.write method isn't used that way, you can just assign the value to the property. You can also use the jQuery val method to set the text.

Besides, you use three different variables in the code, which I think should be the same:

var msg = '<%=completehtml%>';
for(var i = 0, j = $.wordStats.topWords.length; i < j && i <= count; i++) {
  msg += $.wordStats.topWords[i].substring(1) + ', ';
}
$('#textarea').val(msg);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.