I have been having a lot of issues as I try to insert ComboBox values into the Ajax Html editor. I have seen a few questions on here related, and I've tried several of the scripts that are listed as accepted answers, but I still cannot get the values to insert at all. I am using Visual Studio 2010, and it is an ASP.Net WebApp. I cannot for the life of me understand why it will not insert the values, when people obviously have no issues with it. I am trying to insert values from the ComboBox to act as placeholders for Database Values that will be inserted at a later time. I'll post my code here, and I would really appreciate any help or advice anyone can offer.
I have tried several different scripts in an attempt to get this working, but none have yielded any results. The furthest I was able to get was one of the scripts appeared to refresh the page on the SelectedIndex Changed event, and wipe any content that existed in the editor. That wasn't at all helpful, and I could not understand why it even did that.
<asp:ComboBox ID="ComboBox1" runat="server">
<asp:ListItem Value="%meternumberFieldHolder%">Meter Number</asp:ListItem>
<asp:ListItem Value="%accountnumberFieldHolder%">Account Number</asp:ListItem>
</asp:ComboBox>
<br />
<cc1:Editor ID="Editor1" runat="server" Height="500px" />
<script type="text/javascript">
$(document).ready(function () {
$('#<%:ComboBox1.ClientID%>').change(function () {
var cbtext = $('#<%:ComboBox1.ClientID%> option:selected').text();
var cbtext = ' [' + ddltext + '] '
InsertAtCursor(Editor1, cbtext);
});
});
function InsertAtCursor(myField, myValue) {
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
else if (myField.selectionStart == 0 || 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>
This is adapted from an answer I found here
http://stackoverflow.com/questions/10509707/insert-text-at-cursor-position-in-ajax-html-editor-using-client-script/10554972#10554972[
^]
And people there seem to have no issues with this, but I cannot get it to work.