Posting a Molfile in a Form


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

  1. Add a ChemWriter instance to the page and assign an id, e.g., 'chemwriter'.
  2. Add a hidden text field to the page and assign an id, e.g., 'text-display'.
  3. Add a submit button to the page with an onClick attribute set to a JavaScript function, e.g., 'transferMolfile()'.
  4. Implement the transferMolfile() function.

The transferMolfile() function might consist of:

function transferMolfile() {
  var chemwriter = document.getElementById('chemwriter');
  var display = document.getElementById('text-display');
    
  display.value = chemwriter.getMolfile();
}

The transferMolfile() function will execute prior to form submission, enabling the inclusion of the molfile as part of an HTTP POST request.