Question

I have a textarea with some default text named TextArea like this:

<p><textarea name="TextArea">default text</textarea></p>

I set the focus to it using:

Sub Window_OnLoad
    TextArea.Focus
End Sub

Is there a way I can have the cursor at the start of default text rather than the end? I guess it has something to do with "SelStart" but I can't work out how to use it and google isn't helping.

Sorry if this is a basic question, it's my first real hta/vbscript and I'm learning as I go.

Thanks

Was it helpful?

Solution

TextArea.Focus put the cursor at the beginning of the text when I tested it. You can move it using the SendKeys method:

Sub Window_OnLoad
  TextArea.Focus
  CreateObject("WScript.Shell").SendKeys "^{Home}"
End Sub

The SelStart and SelEnd properties apply to textbox controls in Visual Basic forms, not to HTML <textarea> elements.

For more sophisticated cursor handling in textareas you probably need JavaScript.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top