Click to See Complete Forum and Search --> : Find Cursor Position in a textbox in term of number
WebGuy
04-29-2003, 09:35 AM
Hi folks!
Can you give me a hand on this one?
After retrieving a record from the database and displaying one of its text field in an input-type textbox, I click on a word and it'll store or show the current position of cursor in a variable. I have no success with IE's caretPos.
I'll be very appreciated for any response.
Thank you for reading this thread.
thukhoa@hotmail.com
WebGuy
04-30-2003, 12:51 PM
Dave,
check this faq site out:
http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
Son Le
WebGuy
05-01-2003, 12:49 PM
Dave,
It would be very helpful if you can show me how to get the position (numeric value) of the cursor OR the position on the input-type textbox where you point & click your mouse. ie. the input textbox has a mask ???-????-?? when you click any where but "-" (hyphen), a function should return a variable, let's say, pos = 4 if you click on the first "?" of the second section (which are separated by the hyphens) of the mask.
Thanks for reading.
Son Le
Manoj dotnet
08-02-2010, 06:34 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Put slected value in textarea</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/CSS">
</style>
<meta content="MSHTML 6.00.2900.2963" name="GENERATOR">
</head>
<body scroll="auto">
<script type="text/javascript">
function storeCaret(textEl){textEl.caretPos = document.selection.createRange().duplicate(); }
function insertAtCaret (textEl, text){ if (textEl.createTextRange && textEl.caretPos) {textEl.caretPos.text=text;} else{ alert('no carat'); } }
function insertCode()
{
var subject=document.getElementById('myTextarea');
if (document.selection)
{
insertAtCaret(document.getElementById('myTextarea'),'[' + document.getElementById('selectList').value + ']' );
}
else if (subject.selectionStart || subject.selectionStart=='0')
{
var str=subject.value;
var a=subject.selectionStart, b=subject.selectionEnd;
subject.value=str.substring(0,a)+arguments[0]+(arguments[1]?str.substring(a,b)+arguments[1]:"")+str.substring(b, str.length);
return;
}
};
function insertText()
{
var inp=document.getElementById('selectList');
insertCode('[' + inp.value + ']');
}
</script>
<br>
<textarea id="myTextarea" style="height: 200px; width: 300px" onclick="storeCaret(this);"
onselect="storeCaret(this);" onkeyup="storeCaret(this);"></textarea>
<br />
<select id="selectList">
<option value="delhi">Delhi</option>
<option value="jaipur">Jaipur</option>
<option value="Kolkata">Kolkata</option>
</select>
<input type="button" value="Insert Text" onclick="insertText();">
</body>
</html>
Manoj dotnet
08-02-2010, 06:36 AM
hey..
this code works fine in IE and FF .. and used to insert the selected value of dropdown list in the textarea where user last clicked.