I'm trying to submit the contents of the editor to my server onChange. I'm using node.js, socket.io, jquery, and codemirror.
This is my code thus far (client-side) ("code.server" means that I'm sending the code-textarea contents to my server. I use "code.client" to send information back to the client):
<textarea id="code"></textarea>
<script>
var socket = io.connect();
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
lineNumbers: true,
matchBrackets: true,
onChange: function(){
var value = getValue();
socket.emit("code.server", value);
}
});
</script>
Yet it isn't working. What am I doing wrong? I could submit the contents of the textarea before I added CodeMirror:
<script>
$("#code").keyup(function () {
var value = $(this).val();
socket.emit("code.server", value);
}).keyup();
</script>
I used jQuery, in case that wasn't clear.
And now, after adding codemirror, I can't get the contents and send them to the server. What is going on? Thank you for helping me, I've been working on this problem for several days, it's driving me crazy.
From the code above the getValue
method is undefined, I think you want either this.getValue
or editor.getValue
.