I tried to change the value in code mirror editor but it doesn't work.
function myFunction() {
getFi();//get the new code
editor.setValue(fi);
editor.refresh();
}
I also tried to change the text area value, but it doesn't work.
function myFunction() {
getFi();//get the new code
document.getElementById('code').value = fi;
editor.refresh();
}
Edit: partial code, here the initialization of the editor and the function that should load the code
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src='http://codemirror.net/lib/codemirror.js'></script>
<script src='http://codemirror.net/mode/xml/xml.js'></script>
<script src='http://codemirror.net/mode/javascript/javascript.js'></script>
<script src='http://codemirror.net/mode/css/css.js'></script>
<script src='http://codemirror.net/mode/htmlmixed/htmlmixed.js'></script>
</head>
<body>
<textarea id="code" name="code" ></textarea>
<button type="button" id="execute" onclick="myFunction()">Load Code</button>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
mode: 'text/javascript',
tabMode: 'indent',
lineNumbers: true,
lineWrapping: true,
autoCloseTags: true,
indentWithTabs: true
});
function myFunction() {
getFi();//get the new code
editor.setValue(fi);
editor.refresh();
}
function getFi(){
/*get new code from a file*/
}
</script>
</body>
</html>