Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTA - Move Cursor in a Field 1

Status
Not open for further replies.

Skie

Programmer
Jun 21, 2004
475
0
0
US
Is it possible to set a key so that it moves the cursor to a specific location in the input text field.

Sub field_onKeyPress
Select Case window.event.keycode
Case 96
'Code to move cursor to position X in the field.
End Case
End Sub

The only thing I can think of is using SendKeys to send "right" keystrokes to the position. Is there any way to simply say MoveCursorLeft 20?
 
You need to call the move method on the text range
Code:
<html>

<head>
<title>Focus</title>
<script type="text/VBScript">
dim fields(2)
sub init
   set fields(1) = document.GetElementById ("F1")
   set fields(2) = document.GetElementById ("F2")
end sub
sub select_OnClick (col)
   dim radBtnGrp, radBtn, f1, f2, ffocus
   set radBtnGrp = document.theform.select
   call init
   for each radBtn in radBtnGrp
      if radBtn.checked then
         set ffocus = fields(cint(radbtn.value))
         call ffocus.focus
         set range = ffocus.createTextRange ()
         range.collapse true
         range.moveEnd "character", col
         range.moveStart "character", col
         range.select
      end if
   next
end sub
</script>
</head>

<body>
<form name="theform">
   Field 1 <input type="text" id="F1" name="T1" value="Cupid" size="20"><br/>
   Field 2 <input type="text" id="F2" name="T2" value="Red Buttons" size="20"><br/>
   <input type="radio" name="select" value="1" onclick="vbscript:select_OnClick (2)" checked >Goto Field 1, column 2<br/>
   <input type="radio" name="select" value="2" onclick="vbscript:select_OnClick (5)">Goto Field 2, column 5<br/>
</form>
</body>

</html>
 
This is exactly what I was looking for. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top