Click to See Complete Forum and Search --> : pass string from javascript to applet


Apan
11-05-2003, 06:41 AM
Hi
Im trying to pass a String from a form via a javascript to an applet in another frame.

I have tried like this:
Script in the Form_frame:
{
var theText=document.theForm.theName.value;
parent.applet_frame.aScriptFunction(theText);
}
and then in another script in the Applet_frame:

function aScriptFunction(aText)
{
document.theApplet.aFunction(aText);

}


and Applet:
public void aFunction(String someText)
{
System.out.println("Applet: got text:"+someText);
}

Then I got a Java.lang.Exception error: aFunction{0}:There is no such method.

Any suggestions??

Khalid Ali
11-05-2003, 07:16 AM
looks good at the first glance,make sure that your browser is correctly configured to use most current JVM(I am guessing this error si being shown in IE)

clairec666
11-05-2003, 07:20 AM
Otherwise, you could use document.write() to insert the whole applet into the page, so you can add in the parameters from the javascript variables.
This would be a bit messy though

Apan
11-05-2003, 07:31 AM
Im using Java 2 v.1.4.2_01

And I like to have the applet in a separate frame. Then it remains in its correct state even when the page in the other frame changes.

Could it be some incompatibility between the String types of javascript and javaApplet? Seems unlikely..

fredmv
11-05-2003, 07:43 AM
In the <applet> tag, make sure you have the mayscript attribute defined.<applet mayscript="mayscript"></applet>This allows you to script the applet through JavaScript. ;)

Apan
11-05-2003, 08:02 AM
Amazing how blind one can be...
been looking at the code over and over and have not seen that I had written 'mayscript' and not finished the 'sentense' like mayscript="mayscript". Thanks alot for making me see :)

fredmv
11-05-2003, 08:07 AM
No problem. However, if the text mayscript was present within the <applet> tag it should have worked! Under certain DOCTYPEs the way I did it is required though.