Question

I created a textarea to highlight text for C# code using CodeMirror. But when I try to get the value of textarea I'm failing.

I'm creating my editor as

var editor = CodeMirror.fromTextArea(document.getElementById("txtCode"), {
    lineNumbers: true,
    mode: "text/x-csharp",
    matchBrackets: true
});

When I write some meaningless words and try to get value like this:

alert(document.getElementById("txtCode").value); 

It returns:

if(true){}else{}

When I try to get it like:

alert(document.getElementById("txtCode").getValue());

The browser gives the error "Uncaught TypeError: Object # has no method 'getValue'"

How can I get this value?

Was it helpful?

Solution

Use editor.getValue();

alert(editor.getValue());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top