Hi,
I have a problem with finding the cursor position from a inputText field component.
Used the following java script code to achieve it. The same functionality is working fine if i run in a simple html page. But when used the same javascript inside jsff it is not returning the cursor position.
var adfComponent = AdfPage.PAGE.findComponentByAbsoluteId("r1:1:it3");
var adfComponentClientId = adfComponent.getClientId();
var div = document.getElementById(adfComponentClientId + '::content');
div.focus();
var docSelectionRange = document.selection.createRange();
docSelectionRange.moveStart ('character', -div.value.length);
var iCaretPos = docSelectionRange.text.length;
alert("iCaretPos --> "+iCaretPos); ---> This statement always returning '0'. Instead, i want the cursor position inside the text box.
Please let me know what am i missing.
For your reference, sending the sample html page which is working fine with the same kind of code.
<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) {
var iCaretPos = 0;
alert(oField);
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);
}
</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">
</form>
</body>
</html>
Thanks & Regards,
Kiran Konjeti
Edited by: Kiran Konjeti on Feb 6, 2012 12:00 PM