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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find current TEXTAREA row

Status
Not open for further replies.

ionutdinulescu

Programmer
Joined
Jun 11, 2002
Messages
59
Location
GB
Is there any method to get the current row (the row in which the cursor is) in a TEXTAREA object ?

Also is it possible to go to a given row/column using Javascript ?
 

I don't believe these are possible. If they are, I'm betting they will be IE only.

Dan

 
I don't mind if this is only IE specific.
Can anyone give me a code example for this ???
 
This will output the col, row. But I don't think its possible to go to a given row. I'll keep trying though.
Code:
<html>
  <head>
    <title>Test</title>
    <script type="text/javascript">
function getCursorPos(ta){
  if(ta.value==""){
    alert("0, 0");
  }
  else{
    i=0;
    ta.pos.moveStart('character', -1);
    while (ta.value.substr(0,i)!=ta.pos.text){
      ta.pos.moveStart('character', -1);
      i++;
    }
    alert(i%ta.cols + ", " + (i-i%ta.cols)/30);
  }
}
    </script>
  </head>
  <body>
    <form>
      <div>
        <textarea onclick="this.pos = document.selection.createRange().duplicate();" onfocus="this.pos = document.selection.createRange().duplicate();" onkeyup="this.pos = document.selection.createRange().duplicate();" rows="10" cols="30"></textarea>
        <input type="button" value="get cursor pos" onclick="getCursorPos(this.parentNode.firstChild)" />
      </div>
    </form>
  </body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top