Click to See Complete Forum and Search --> : Selecting Focus at end of string in TEXTAREA


learninghtml
10-23-2003, 01:54 AM
Hi,
I have a text area with some text already entered. I want to be able to set the focus to this form object automatically.

But when I use the following...


document.email.message.focus();


It selects the TEXTAREA, but leaves the cursor at the start of the TEXTAREA and doesn't put the cursor at the end of the text that is already there. I want the cursor to appear at the end of the already entered text.

Is there a way to do this?

Many thanks in advance.

ccoder
10-23-2003, 09:49 AM
Try this:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function EOT(txt)
{
var range = txt.createTextRange();

range.move("textedit");
range.select();
}
</SCRIPT>
</HEAD>
<BODY>
<TEXTAREA COLS=80 ROWS=4 WRAP=soft ONFOCUS="EOT(this);">Testing EOT in a textarea block</TEXTAREA>
<BR><BR>
<INPUT TYPE=text SIZE=50 VALUE="Testing EOT in an input block" ONFOCUS="EOT(this);">
</BODY>
</HTML>

It worked for both 'text fields' in IE 5.5.

pelegk1
10-23-2003, 09:55 AM
range.move("textedit");

whats the move property does?

ccoder
10-23-2003, 11:07 AM
The syntax is move("unit"[, count]), where unit can be "character", "word", "sentence" or "textedit" and count is optional (with a default of 1) and can be positive or negative. "textedit" specifies the entire text range.

move does 2 things. First it collapses the range to become an insertion point at the end point of the collapsed range. Then it moves the insertion point forward or backward count units.

To clarify my previous post, this is supported by IE 4 and above. It is not supported through NN 6. I don't know it NN 7 or other browsers support it.

learninghtml
10-23-2003, 06:04 PM
Hi guys,
That works a treat.

Thank you, Thank you, Thank you, Thank you - Is that enough? - Nope don't think so... -Thank you, Thank you, Thank you. That's better.


Seriously, thank you very much guys.

Best regards