ChemWriter

ChemWriter 2

Send a Molfile to a Server

Molfiles can be submitted as HTML form data using ChemWriter. This technique involves four steps:

  1. Add an editor instance to the page and assign it a name, e.g., editor.
  2. Add a hidden text field to the page and assign an id, e.g., molfile.
  3. Add a submit button to the page with an onClick attribute set to a JavaScript function, e.g., transfer().
  4. Implement the transfer() function.
<!DOCTYPE HTML> 
<html>
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, IE=9" />
    <link rel=stylesheet href="chemwriter.css" type="text/css" media=screen />
    <script src="chemwriter.js"></script>
  </head>
  <body>
    <div id="editor"></div>
    <form action="http://www.chemspider.com/WebAPI.aspx" method="post">        
      <input name="molfile" id="molfile" type="hidden" />
      <input type="submit" value="Search ChemSpider" onclick="transfer()" />
    </form>
    <script>
      var editor = chemwriter.loadEditor('editor');

      var transfer = function() {
        document.getElementById('molfile').value = editor.getMolfile();
      };
    </script>
  </body>
</html>