RonPK

msg:1474639 | 8:08 pm on Oct 8, 2005 (gmt 0) |
Will a simple focus() be enough? document.nameOfMyForm.nameOfInputBox.focus();
|
YorkshireSteve

msg:1474640 | 8:10 am on Oct 10, 2005 (gmt 0) |
Thanks for the reply. I currently us onFocus() but I need to place the user's cursor before the entered text. For example, consider the following being the contents of an HTML textarea:
---- Original Message ---- Hello. This is my message.
By using onFocus() the user's cursor would be placed at the end of the text, whereas they would want their reply to appear before the top of the original message.
|
RonPK

msg:1474641 | 9:19 am on Oct 10, 2005 (gmt 0) |
Ah, I see. Here's a small function to manipulate the caret position. It actually creates a selection if selStart and selEnd are not equal. function setSelRange(inputEl, selStart, selEnd) { if (inputEl.setSelectionRange) { inputEl.focus(); inputEl.setSelectionRange(selStart, selEnd); } else if (inputEl.createTextRange) { var range = inputEl.createTextRange(); range.collapse(true); range.moveEnd('character', selEnd); range.moveStart('character', selStart); range.select(); } } Call the function with setSelRange(document.formName.replyHere, 0, 0) to set the caret at the start of the textarea called 'replyHere' (or input element).
|
YorkshireSteve

msg:1474642 | 10:19 am on Oct 10, 2005 (gmt 0) |
Fantastic! Thanks a lot - it works perfect! :) Steve
|
kedsri

msg:1474643 | 6:49 pm on Oct 14, 2005 (gmt 0) |
Mr.RonPK I have a Textarea and in that Text area i am selecting values from a javascript child window. let say the Parent window as par.html and child window as child.html. From the child.html i send "ABC" values as opener.parent.par.txtBox.value. so this value ABC goes into the par.html text area as ABC. Now if i want ABXYZC in my text area. so i have to place my cursor in between AB and the values XYZ from the child window shd be inserted as ABXYZC. how to achieve this? your help is highly appreciated. Thanks, Kedar
|
|