(Please don't top post)
Try:
document.form.txtBox.value.substr(2, 1);
That will work too, as will .substring(2,3)
(I hope you picked the right one, I can never remember which is which
As for why .value[2] does not work... I might be a little off here, but I
think the general idea is that a string is not so much a simple array of
chars as it is an object, one based on (or of) the string class.
A little off, yes, and a little on too.
Strings in Javascript are primitive values. It's one of the five types of
non-object values (the other being number, boolean, null and undefined).
Strings are immutable and have no properties. Not even "length".
What happnes when you write
"foo".length
is that the Javascript interpreter sees a property lookup. It then
converts the value before the "." to an object. Primitive values are
converted to objects using the appropriate constructor (String, Boolean
or Number, null and undefined cannot be converted to objects and gives
an error).
So, the above is equivalent to
new String("foo").length
The String object (or rather its prototype) has methods like "charAt",
"substr", and "split". It also has the property "length" which is set
to the length of the string used to create the object.
So, strings are not arrays of chars. In Netscape 4, the String object
could be accessed using integer indices, but later browsers dropped
that. Strings are not instances of the string class, but they are
converted to such if needed.
/L