Search code examples
phpjavascriptjquerycodemirror

CodeMirror save itself onBlur


I want to save all CodeMirrors generated by PHP itself onBlur. Here is what I am talking about:

        while ($db_field = mysql_fetch_assoc($result)) {
         ...
            var editor = CodeMirror.fromTextArea(document.getElementById("id'.$db_field['id'].'"), {
              lineNumbers: true,    
              matchBrackets: true,
              mode: "application/x-httpd-php",    
              onBlur: id'.$db_field['id'].'.save()
            });
         ...
         }

But it don´t work ... FireBug says: "id1 is not defined" ... how to do it?


Solution

  • I found bug in my code:

            var id'.$db_field['id'].' = CodeMirror.fromTextArea(document.getElementById("id'.$db_field['id'].'"), {
            lineNumbers: true,    
            matchBrackets: true,
            mode: "application/x-httpd-php",
            onBlur: function(){
              id'.$db_field['id'].'.save();
            },
            onChange: function(){
            $("#changeimg").show();
            }     
            });
    

    This works like a charm