A bit easier. No "eval" is necessary. Just say

document["jmol"+i].script(s)

In JavaScript,

xxxxxx["yyy"]

is identical to

xxxxxx.yyy

DON'T NAME THEM ALL THE SAME!!!! oy! Even naming a global variable the same as an ID value in a div can cause great problems.



Bob

timothy driscoll wrote:

Hi all,

I am new to the jmol users list, and relatively new to jmol. I am an
experienced Chime tutorial author, learning how to write tutorials
in jmol applet form. But I am not very experienced with
javascript...

I'm looking for some help with what I think is a really basic
question. I am using the jmol javascript library, for which I am
very grateful (wow, what a useful thing to have access to! Thanks!)
I would like to learn how to use the jmolButton method to send a
command or script to two (or more) jmol applets on the same page,
with a single activation (click) of the button.



off the top of my head, not having looked at the jmolButton code:


1. name the applets on your page so they include numbers; ie jmol1, jmol2, jmol3, etc. then set up your button to send the script via an array:

/*
var s = "#my script commands";

for (var i=1;i<4;i++) {
eval("document.jmol"+i+".script(\""+s+"\")");
}
*/




alternatively, if your js will always 'know' how many applets exist:

/*
var s = "#my script commands";

document.jmol1.script(s);
document.jmol2.script(s);
document.jmol3.script(s);
*/




2. name all your applets the same. (this may crash some browsers, if my hazy memory serves, but it is simpler than 1).



hth,

tim

--

Robert M. Hanson, [EMAIL PROTECTED], 507-646-3107
Professor of Chemistry, St. Olaf College
1520 St. Olaf Ave., Northfield, MN 55057
mailto:[EMAIL PROTECTED]
http://www.stolaf.edu/people/hansonr

"Imagination is more important than knowledge."  - Albert Einstein



-------------------------------------------------------
This SF.Net email is sponsored by: thawte's Crypto Challenge Vl
Crack the code and win a Sony DCRHC40 MiniDV Digital Handycam
Camcorder. More prizes in the weekly Lunch Hour Challenge.
Sign up NOW http://ad.doubleclick.net/clk;10740251;10262165;m
_______________________________________________
Jmol-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to