Dean,

Many thanks.  I've got it working perfectly now.  The only tweak I had  
to make to your suggestion was to change loadString to  
eval(loadString).  From my reading I had thought that innerHTML was  
not part of the Standard and so I was trying not to use it.   
Interestingly my previous approach (creating a new jmol object) now  
works if I use eval(loadString) as long as I do not include the  
jmolSetDocument(false).  In this case it wipes the page and correctly  
displays the jmol applet.  When I add the jmolSetDocument(false) it  
writes [object Object] where the applet should be.  So the  
jmolSetDocument(false) is somehow messing up creating the jmol object  
correctly.  Dean, you were a great help.  Might someone help me figure  
out this other way too?  I would like to be as standards compliant as  
possible.

Here is the current code that works (thanks Dean):
<script type="text/javascript">
        var divInc = 0;
        function newJmolDiv(molecule) {
                var newDiv = document.createElement('div');
                var jmolID = 'jmolDiv_' + (divInc++);
                newDiv.id = jmolID;
                document.body.appendChild(newDiv);
                var loadString = "\"load ../Jmol/jmol/models/" + molecule + 
"\"";
                jmolInitialize("jmol");
                jmolSetDocument(false);
                newDiv.innerHTML = jmolApplet(400, eval(loadString));
        }
        function appletReady() {
                var atomSetArray = 
jmolGetPropertyAsArray("atomInfo","atomno<5");
                alert (atomSetArray[0].info);
        }
</script>

Here is the code that almost works.  Without jmolSetDocument(false) it  
clears the page and loads the applet.  With jmolSetDocument(false) it  
puts [object Object] in the new div.
<script type="text/javascript">
        var jmolObject = Class.create();
        jmolObject.prototype = {
                initialize: function(molecule){
                        jmolInitialize("jmol");
                        jmolSetDocument();
                        var loadString = "\"load ../Jmol/jmol/models/" + 
molecule + "\"";
                        alert(loadString);
                        jmolApplet(400, eval(loadString));
                }
        };
        var divInc = 0;
        function newJmolDiv(molecule) {
                var newDiv = document.createElement('div');
                var jmolID = 'jmolDiv_' + (divInc++);
                newDiv.id = jmolID;
                document.body.appendChild(newDiv);
                newDiv.update(new jmolObject(molecule));
        }
        function appletReady() {
                var atomSetArray = 
jmolGetPropertyAsArray("atomInfo","atomno<5");
                alert (atomSetArray[0].info);
        }
</script>



***********************************************
Jeff Hansen
Department of Chemistry and Biochemistry
DePauw University
602 S. College Ave.
Greencastle, IN 46135
[EMAIL PROTECTED]
***********************************************


On Aug 23, 2008, at 11:47 AM, [EMAIL PROTECTED]  
wrote:

> Jeff,
>
>  I remember being similarly confused when I first started playing with
> Javascript and the DOM.  By default, the Jmol.js library functions  
> write the
> necessary HTML to the current document when they are called.  So in  
> your
> case, calling jmolApplet is overwriting everything, including your
> controls.  To change this behavior, you need to call  
> jmolSetDocument(false).
> The beauty of the Jmol.js library is that all of the functions  
> return HTML
> that you can then assign to a variable.
>
>  The other thing I've found very useful is innerHTML (some people  
> love it,
> others hate it; I've learned to live with it).  In your case, you  
> can do
> something as simple as:
>
>  jmolSetDocument(false);
>  newDiv.innerHTML = jmolApplet(400, loadString);
>
> (Of course, within your example, you will need to decide where you  
> want to
> put this - but I hope it gives you some idea where to go.)  Good  
> luck with
> your pages.
>
> Dean


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to