Avatar of lulu50
lulu50
Flag for United States of America asked on

Send json data to a text editor

Hi,

I'm having problem sending "Json" data to a text editor

Can you please help?

 $("#SelectAFunctionFromList").change(function (event) {
            debugger;
            var GetValue = $(this).val();
            $('#HiddenFieldForSelectedFunctionID').val(GetValue);
            //reset select group
           // $('#FunctionTextArea').val("");
            var method = $('#FunctionPartialViewForm').attr("method").toLowerCase();
            var action = $('#FunctionPartialViewForm').attr("action");
            var data = $('#FunctionPartialViewForm').serialize();
            $.ajax({ method: method, url: action, data: data }).done(
                function (json) {

                  //Here I want to send my json data to my text editor called "FunctionTextArea" 
                    alert(json);
                    editor .value =  $("#FunctionTextArea").val(json);


                });
        });




      jQuery(function () {
            var editor = new Jodit("#FunctionTextArea");
        });

Open in new window

JavaScriptjQueryAJAXJSON

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon
leakim971

editor .value =  $("#FunctionTextArea").val( JSON.stringify(json) ); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

Open in new window

lulu50

ASKER
I get this error:

Unhandled exception at line 9, column 31833

0x800a139e - JavaScript runtime error: value must be string


 $("#SelectAFunctionFromList").change(function (event) {
            debugger;
            var GetValue = $(this).val();
            $('#HiddenFieldForSelectedFunctionID').val(GetValue);
            var method = $('#FunctionPartialViewForm').attr("method").toLowerCase();
            var action = $('#FunctionPartialViewForm').attr("action");
            var data = $('#FunctionPartialViewForm').serialize();
            $.ajax({ method: method, url: action, data: data }).done(
                function (json) {

                    //alert(json);
                    //var editor = new Jodit('#FunctionTextArea');
                    //editor.setEditorValue('some value')

                    editor.value = $("#FunctionTextArea").val(JSON.stringify(json));

                });
        });

Open in new window

ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lulu50

ASKER
If I do this, it will create a new text area with the json data in it.
but I don't want to create a new text area

        $("#SelectAFunctionFromList").change(function (event) {
            debugger;
            var GetValue = $(this).val();
            $('#HiddenFieldForSelectedFunctionID').val(GetValue);
            var method = $('#FunctionPartialViewForm').attr("method").toLowerCase();
            var action = $('#FunctionPartialViewForm').attr("action");
            var data = $('#FunctionPartialViewForm').serialize();
            $.ajax({ method: method, url: action, data: data }).done(
                function (json) {

                
                  //It create a new "FunctionTextArea" instead of writing to an existing one. 
                  // If I remove the first line it will post the data to the parent window textbox instead of the "FunctionTextArea" 

                    var editor = new Jodit('#FunctionTextArea');
                    editor.value = JSON.stringify(json);


                });
        });

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
leakim971

put that line 15 before line 1
lulu50

ASKER
Great!!!

It's working

Thank you so much!!!!!!

You're the best!!!!
leakim971

pas de problème
you welcome
have a nice weekend
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.