Therefore, I need to use scrollTop to get the location of the highlighted material, and then send the cursor back to that position once the button is pressed. I've tried looking for this on google, but all I find are auto scrolling scripts.
I'm guessing I would need to get the position onClick, and then after I have fun the function that adds the tag, have the JavaScript take the cursor to it's original position. Problem is, I don't know how to implement that.
Any help would be greatly appreciated
My code basically looks like this:
Code: Select all
<script type="JavaScript">
function addPTag(ta,pTag)
{
//Adds tags to the textarea at highlighted text location
}
</script>
<body>
<button onclick="addPTag(document.getElementById('text'),'b')" value="bold"></button>
<textarea id="text" rows="20" cols="80">
Ipsum epsum lorem indige....
</textarea>
</body>