Hello,
I am trying to restrict to maximum type 60 words in a textbox.
I have tried to put a code that check if we have more than 60 words.
The code restricts to 60 words but when I loop the textboxes words and put back the string (up to 60 words) the string says:
"undefined undefined undefined undefined... etc"
Why does this happen? what is undefined?
<asp:TextBox ID="TextBox26" runat="server" Height="209px" TextMode="MultiLine" onkeyup="return countwordsarticle();"
Width="650px" Font-Names="Arial" Font-Size="10pt" ForeColor="#333333"></asp:TextBox>
function countwordsarticle() {
var str1 = document.getElementById("TextBox26").value.replace(" ", " ").trim();
var words1 = str1.split(' ').length;
//If more than 60 words only show 60
if (words1 > 60) {
var newstr;
for( var i = 0; i < 60; i++ )
{
newstr = newstr + words1[i] + " ";
}
//Put to textbox
document.getElementById("TextBox26").value = newstr.toString();
}
return false;
}