[CLOSED] Add Text to the current cursor-position in a textarea or htmleditor
Hello,
is there a way to add text to the current cursor-position of a textarea or htmleditor or whatever...?
E.g. i have the following code:
Code:
<ext:ToolbarButton ID="AddLinkButton" runat="server" StandOut="true" Icon="LinkAdd"
Text="Link hinzufügen">
<Listeners>
<Click Handler="#{HtmlEditor}.setValue(#{HtmlEditor}.getValue()+addLink(#{PageUid}.getValue(),#{DataId}.getValue(), #{DataId}.getText(), #{LinkName}.getValue()))" />
</Listeners>
</ext:ToolbarButton>
My AddLinkButton adds a special linl to my HtmlEditor. But -of course- the link is always added at the end of the HtmlEditor-TextArea.
Is there a way to get the current (or last) cursor-position of the HtmlEditor and add the link or any other string there?
Regards,
Martin
RE: [CLOSED] Add Text to the current cursor-position in a textarea or htmleditor
Hi,
Please see the following sample
Code:
<%@ Page Language="C#" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function insertAtCursor(myField, myValue) {
myField = myField.el.dom;
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server">
</ext:ScriptManager>
<ext:HtmlEditor ID="Editor1" runat="server">
</ext:HtmlEditor>
<ext:Button runat="server" Text="Paste">
<Listeners>
<Click Handler="Editor1.insertAtCursor('&nbsp;Some&nbsp;text&nbsp;');" />
</Listeners>
</ext:Button>
<ext:TextArea ID="Editor2" runat="server" Width="300" Height="100"></ext:TextArea>
<ext:Button runat="server" Text="Paste">
<Listeners>
<Click Handler="insertAtCursor(Editor2, ' Some text ');" />
</Listeners>
</ext:Button>
<ext:TextField ID="Editor3" runat="server" Width="300"></ext:TextField>
<ext:Button runat="server" Text="Paste">
<Listeners>
<Click Handler="insertAtCursor(Editor3, ' Some text ');" />
</Listeners>
</ext:Button>
</form>
</body>
</html>
RE: [CLOSED] Add Text to the current cursor-position in a textarea or htmleditor
Thank you very much.
It works fine!
RE: [CLOSED] Add Text to the current cursor-position in a textarea or htmleditor
hi,
We are using just HTMLEditor and no specific textArea.we want insert the text at cursor position.
we are using following code.
Code:
Editor1.insertAtCursor("some text");
we have tried with above code,but doesn't work in IE .It works well in all other browsers.in IE it inserts at top
position.
We also tried your code but it also doesn't work for us.
please help to resolve this issue in IE.
Thanks,
YobNet Team.
RE: [CLOSED] Add Text to the current cursor-position in a textarea or htmleditor