jQuery > Update inline script on form submission
<p>I am using the <a href="http://web.chemdoodle.com/components.php" rel="nofollow">ChemDoodle Web Components</a> to display molecules on a web page. Basically, I can just insert the following script in my page and it will create an HTML5 canvas element to display the molecule.</p>

<pre><code>&lt;script&gt;
    var transform1 = new TransformCanvas('transform1', 200, 200, true);
    transform1.specs.bonds_useJMOLColors = true;
    transform1.specs.bonds_width_2D = 3;
    transform1.specs.atoms_useJMOLColors = true;
    transform1.specs.atoms_circles_2D = true;
    transform1.specs.backgroundColor = 'black';
    transform1.specs.bonds_clearOverlaps_2D = true;
    transform1.loadMolecule(readPDB(molecule));
&lt;/script&gt;
</code></pre>

<p>In this example, "molecule" is a variable that I have defined in an external script by using the jQuery.ajax() function to load a PDB file. This is all fine and good.</p>

<p>Now, I would like to include a form on the page that will allow a user to paste in a PDB molecule definition. Upon submitting the form, I want to update the "molecule" variable with the form data so that the ChemDoodle Web Components script will work its magic and display molecule defined by the PDB definition pasted into the form.</p>

<p>I am using the following jQuery code to process the the form submission.</p>

<pre><code>$(".button").click(function() {  
 // validate and process form here

    //hide previous errors
    $('.error').hide();

    //validate pdb textarea field
    var pdb = $("textarea#pdb").val();
    if (pdb == "") {
        $("label#pdb_error").show();
        $("textarea#pdb").focus();
        return false;
    }
    molecule = pdb;

});
</code></pre>

<p>This code is setting the "molecule" variable upon the form submission but it is not being passed back to the inline script as I had hoped. I have tried a number of variations on this but can't seem to get it right. Any clues as to where I might be going wrong would be much appreciated.</p>
