Sign in to follow this  
Followers 0
DeltaRocked

JavaScript to Autoit Caret Pos

3 posts in this topic

#1 ·  Posted (edited)

Hi,

Is it possible to convert this javascript code into Autoit

thanks and regards

DeltaRocked

<html>

 <body style="font-family: tahoma; font-size: 8pt;">
  <script language="Javascript">

   /*
   **  Returns the caret (cursor) position of the specified text field.
   **  Return value range is 0-oField.length.
   */
   function doGetCaretPosition (oField) {

    // Initialize
    var iCaretPos = 0;

    // IE Support
    if (document.selection) { 

    // Set focus on the element
    oField.focus ();
  
    // To get cursor position, get empty selection range
    var oSel = document.selection.createRange ();
  
    // Move selection start to 0 position
    oSel.moveStart ('character', -oField.value.length);
  
    // The caret position is selection length
    iCaretPos = oSel.text.length;
    }

    // Firefox support
    else if (oField.selectionstart || oField.selectionstart == '0')
    iCaretPos = oField.selectionstart;

    // Return results
    return (iCaretPos);
   }


   /*
   **  Sets the caret (cursor) position of the specified text field.
   **  Valid positions are 0-oField.length.
   */
   function doSetCaretPosition (oField, iCaretPos) {

    // IE Support
    if (document.selection) { 

    // Set focus on the element
    oField.focus ();
  
    // Create empty selection range
    var oSel = document.selection.createRange ();
  
    // Move selection start and end to 0 position
    oSel.moveStart ('character', -oField.value.length);
  
    // Move selection start and end to desired position
    oSel.moveStart ('character', iCaretPos);
    oSel.moveEnd ('character', 0);
    oSel.select ();
    }

    // Firefox support
    else if (oField.selectionstart || oField.selectionstart == '0') {
    oField.selectionstart = iCaretPos;
    oField.selectionend = iCaretPos;
    oField.focus ();
    }
   }

  </script>
  <form name="blah">
 
   Text Field: <input type="text" name="nameEdit" value="">
   <input type="button" value="Get Caret" onclick="document.getElementById('where').value=doGetCaretPosition (document.forms[0].elements[0]);">
<input id="where">
   <hr size=1 noshade>
   New Position: <input type="text" name="newPosValue" value="">
   <input type="button" value="Set Caret" onclick="doSetCaretPosition (document.blah.nameEdit, parseInt (document.blah.newPosValue.value));">

  </form>

 </body>

</html>
Edited by deltarocked

Share this post


Link to post
Share on other sites



Ahem... Search, and are your friends.

:)

Lol.... thanks psaltyDS

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0