Click here to Skip to main content
15,886,763 members

Inserting ComboBox values into AJAX HTML editor

MikeVaros asked:

Open original thread
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.NET
<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" />

        &nbsp;<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 for Insertion
                });
            });

            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.
Tags: Ajax, ASP.NET, Editing

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900