Monday, April 25, 2011

How do I get the value of WMD editor?

I am playing around with using the WMD Editor (http://wmd-editor.com/) in my site. I have a really simple question. When I am ready to submit the text to the server; how do I get the output of the editor?

Something like this only returns the 'actual text that user typed in the textarea'

 var jtext = document.getElementById('myTextarea').value;

I would like to get the 'output' of the editor; but I can't figure out how to do that :(

By output; I mean the 'Markdown' or 'Html' output.

From stackoverflow
  • You will need to use javascript to get the contents of the preview div. Based on the demo on the wmd site, the div in question has the class wmd-preview. Not sure why it's not id'd.

    In jQuery, you'd use something like:

    $('#formname').submit(function() {
        $('#hidden_form_element').val($('.wmd-preview').html());
        return true;
    });
    
    shergill : Thanks.. thats what I was not sure about. I was looking for a actual function call or something. So the right thing to do is to save the 'value of the textarea' and the 'value of the preview div'..
    Ryan Graham : There you go. Added some sample code.

0 comments:

Post a Comment