Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java javascript communication

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
US
This is really basic stuff. I am trying to call a method in an applet from a javascript. The applet method just returns a string. It works fine. It's simple. It took five minutes. HOWEVER, it works in every browser except one: Internet Explorer 5.0 on a Macintosh. I can't figure out why.

HTML applet code:
--------------------------
<applet code=&quot;excerpt.class&quot; width=&quot;274&quot; height=&quot;181&quot; name=theapplet></applet>


javascript function:
--------------------------
function callJava()
{
var test = document.theapplet.test()
document.theform.thefield.value=test;
}


applet method:
--------------------------
public String test()
{
String returnStr = &quot;&quot;;
for (int j=0; j<15;j++)
{
for (int i=0; i<15;i++)
{
if (theArray[ i ][j])
{
returnStr += 1;
}
else {returnStr += 0;}
}
}
return returnStr;
}


Anyone? Anyone?
 
My guess is that it has to do with the fact that the Document Object Model changes per operating System and browser. Take a look at and the curious_eye tutorial on how to build cross platform cross browser code for javascript and dhtml. I can post the code if you cannot figure it out :) One other thing , it should be possible to call javascript functions from the applet. Applets can call functions by the use of the URL class, send me an email if your interested and i can send you then code...

later
 
Thanks for the response. I actually solved the problem another way.

I was trying to get a value from the applet to a form field in the HTML page using javascript. What I did instead was to get rid of the HTML form altogether submit the page from the applet directly using appletContext:

[red]try
[tab]{url = new URL(&quot;&#104;ttp://&#119;ww.blah.com/page.asp?gifpixels=&quot;+test()+&quot;&name=&quot;+name.getText()+&quot;&ID=&quot;+getParameter(&quot;ID&quot;));}
catch (MalformedURLException e) { }
getAppletContext().showDocument(url,&quot;_parent&quot;);[/red]

Works OK. This way I'm just sending the values in a querysring. It's simpler and less hacky though it could probably still be better some way or other. As for crossplatform DHTML code there's not really any DHTML going on here but I have a few questions about that regarding another problem. I'll email you.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top