Hello,
I have a form that has a radcombobox and a textarea. When the user selects an item from the radcombobox, I want to insert the selected text into the textarea at the cursor position in the textarea. Here is what I have.
function insertText(sender, eventArgs) { |
var txtPlainText = document.getElementById("<%= txtPlainText.ClientID %>"); |
var DropDownList1 = $find("<%= ddlMergeFields.ClientID %>"); |
if (document.selection) { |
txtPlainText.focus(); |
sel = document.selection.createRange(); |
sel.text = DropDownList1.get_value(); |
} |
//MOZILLA/NETSCAPE support |
else if (txtPlainText.selectionStart || txtPlainText.selectionStart == '0') { |
var startPos = txtPlainText.selectionStart; |
var endPos = txtPlainText.selectionEnd; |
txtPlainTexttxtPlainText.value = txtPlainText.value.substring(0, startPos) + DropDownList1.get_value() + |
txtPlainText.value.substring(endPos, txtPlainText.value.length); |
} |
else |
{ |
txtPlainText.value += DropDownList1.get_value(); |
} |
DropDownList1.set_value(); |
} |
and the combobox is defined as:
<telerik:RadComboBox runat="Server" OnClientSelectedIndexChanged="insertText" ID="ddlMergeFields" Skin="Office2007"> |
<Items> |
<telerik:RadComboBoxItem Text="Merge Fields" Value="test2" /> |
<telerik:RadComboBoxItem Text="test1" Value="test1" /> |
</Items> |
</telerik:RadComboBox> |
The javascript works with a normal dropdownlist, but when i switch it to a radcombobox, it always inserts the text at the top of the textarea, not at the cursor position. Am I doing something wrong?
Also, after inserting the text, i need the combobox selected item to be reset to the first item in the box. How do I do that? I have tried set_value and clearSelection, but neither work.
Please Help.
Patrick