CodeMirror How to get Textarea value-Collection of common programming errors

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?

Originally posted 2013-11-15 09:07:22.