-
August 2nd, 2005, 10:48 PM
#1
In JavaScript, how to get the length of a string?
In JavaScript, how to get the length of a string?
-
August 2nd, 2005, 11:13 PM
#2
Re: In JavaScript, how to get the length of a string?
-
August 3rd, 2005, 04:46 AM
#3
Re: In JavaScript, how to get the length of a string?
<TD>Note:</TD>
<TD>
<TEXTAREA NAME="note" ROWS="5" COLS="35"></TEXTAREA>
</TD>
// Nothing happens
alert( form.note.value.length() );
-
August 3rd, 2005, 09:30 AM
#4
Re: In JavaScript, how to get the length of a string?
Originally Posted by _mynameisno1
alert( form.note.value.length() );
You want:
Code:
alert(form.note.value.length);
Length is not a method of the string attribute, the reason why the parentheses are avoided.
*9-11-01* Never Forget; Never Forgive; Never Relent!
"If we ever forget that we're one nation under God, then we will be a nation gone under." - Ronald Reagan
-
August 3rd, 2005, 08:51 PM
#5
Re: In JavaScript, how to get the length of a string?
-
August 7th, 2005, 10:14 AM
#6
Re: In JavaScript, how to get the length of a string?
Assuming it is in a form:
alert(document.forms[0].note.value.length)
If it is not in a form then use id="note" instead of name="note"
And get it with:
alert(document.getElementById('note').value.length)
or I suppuse you might get it inside the tag with:
alert(document.getElementById('note').innerHTML.length)
Though I'm not sure it should be there based on the standards.
_____________________________________________
Home is a place where, when you go there, they have to take you in. (Robert Frost)
Some of us have no Home. (COBOLdinosaur)
Cd&
-
August 7th, 2005, 10:49 AM
#7
Re: In JavaScript, how to get the length of a string?
Originally Posted by COBOLdinosaur
Though I'm not sure it should be there based on the standards.
I'd stick away from innerHTML. It is simply a Microsoft corruption of DOM. Instead, one could usually use .firstChild.date. However, if it is an input element (text box), the value attribute is best for use.
If you hae name="note", and that is froma databse, and unchangeable, the way to do that would be to use .getElementsByName('note')[0].
document.getElementsByName('') returns an HTMLCollection of elements with that name. 0 refers to the first (and only, probably) element with the name note.
*9-11-01* Never Forget; Never Forgive; Never Relent!
"If we ever forget that we're one nation under God, then we will be a nation gone under." - Ronald Reagan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|