Jquery > Update Inline Script On Form Submission
Solution 1:
Maybe make your inline script a function?
<script>functionLoadMolecule(molecule) {
var transform1 = newTransformCanvas('transform1', 200, 200, true);
transform1.specs.bonds_useJMOLColors = true;
//...etc...
transform1.specs.bonds_clearOverlaps_2D = true;
transform1.loadMolecule(readPDB(molecule));
}
</script>
Then...
$(".button").click(function() {
// validate and process form here//hide previous errors
$('.error').hide();
//validate pdb textarea fieldvar pdb = $("textarea#pdb").val();
if (pdb == "") {
$("label#pdb_error").show();
$("textarea#pdb").focus();
returnfalse;
}
LoadMolecule(pdb);
});
Solution 2:
Edit: I think I massively mis-understood the question. I was thinking you had a textbox of JavaScript code, that you needed to be parsed as JavaScript to form one of your molocules :). On the off-chance I did read the question right, I'll leave this answer here.... :)
You'll have to use dirty eval()
, but be aware of the implications
try {
eval(pdb);
} catch (e) {
// error; syntax error in their code.
};
Setting molecule = pdb
doesn't really make sense. eval
returns the value returned by the last expression (e.g. whatever loadMolecule
returns in your example).
The reason it doesn't work at the moment is because pdb
is simply string (JavaScript doesn't care if it contains valid JavaScript or not; it's just a string!)
Solution 3:
You mention that you're using a form. If it's a real one, do you need to block the page submission? If so, I think you need a return false
somewhere along the successful path to prevent the form from actually submitting.
Post a Comment for "Jquery > Update Inline Script On Form Submission"