Javascript document write
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
try
document.form1.textarea.value= msgcounttext;
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'
})
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);
Besides not having a variable named msgcounttext
, get rid of the document.write
call.
精彩评论