开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜