asking for a textarea's .length produces wrong result?
Hi I have a html form with the following code
<td ><label>
<textarea name="comments" id="comments"
cols="100" rows="3"
onkeyup="illegal()" </td>
when the js function 'illegal' is called part of the code is
cm = document.form1.comments.value
cl = cm.l开发者_运维技巧ength
But what ever the string length is, the result is an additional 13 characters ?
can anybody help me please ?
One problem you have there is that you haven't closed your textarea, though I don't know that it would cause the particular issue you're seeing.
I tried the following simple page:
<html>
<form id="form1" name="form1">
<label>
<textarea name="comments" id="comments"
cols="100" rows="3"
onkeyup="alert(document.form1.comments.value.length)" ></textarea>
</form>
</html>
It works fine -- every time you type, it pops up the number of characters. Correctly. I've tried it in Chrome and in Firefox.
On a textarea you should look for the html content of the textarea element not for the value itself.
精彩评论