Send json data to a text editor

lulu50
lulu50 used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
leakim971Multitechnician
Top Expert 2014

Commented:
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

lulu50Web application

Author

Commented:
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

Multitechnician
Top Expert 2014
Commented:
try this :
editor.value = JSON.stringify(json);

Open in new window

or:
editor.value = json;

Open in new window

lulu50Web application

Author

Commented:
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

leakim971Multitechnician
Top Expert 2014

Commented:
put that line 15 before line 1
lulu50Web application

Author

Commented:
Great!!!

It's working

Thank you so much!!!!!!

You're the best!!!!
leakim971Multitechnician
Top Expert 2014

Commented:
pas de problème
you welcome
have a nice weekend

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial