I am using Codemirror's plugin for textarea but I am not able to retrieve the value of textarea.
Code:
var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-csrc" }); function showCode() { var text = editor.mirror.getCode(); alert(text); }
It is showing the error:
editor.getCode() is not a function.
To get the value of the CodeMirror text editor we need to write some javascript code in the default. js file. $(document).
This could be used to, for example, replace a textarea with a real editor: var myCodeMirror = CodeMirror(function(elt) { myTextArea. parentNode. replaceChild(elt, myTextArea); }, {value: myTextArea.
Getting/Setting Values: var code = editor. getValue(); editor. setValue("new code here");
There's two ways to do this: Find a linter that you can run in the browser, run it on the content, and translate its output into the expected format. Write one from scratch, possibly using the syntax tree kept by the editor.
Try using getValue()
instead of getCode()
.
Pass in an optional argument into getValue(separator) to specify the string to be used to separate lines (the default is \n
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With