Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag 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

Avatar of leakim971
leakim971
Flag of Guadeloupe image

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

Avatar of 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
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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

put that line 15 before line 1
Avatar of lulu50

ASKER

Great!!!

It's working

Thank you so much!!!!!!

You're the best!!!!
pas de problème
you welcome
have a nice weekend