• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using JavaScript to communicate with Applets

 
Lanny Gilbert
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applet that is declared as follows in a JSP page.

<OBJECT classid="clsid:CAFEEFAC-0014-0002-0008-ABCDEFFEDCBA"
width="650" height="530" align="baseline"
codebase="http://java.sun.com/update/1.4.2/jinstall-1_4_2_08-windows-i586.cab">
<PARAM name="code" value="IPETETApplet.class">
<PARAM name="name" value="IPETET">
<PARAM name="id" value="IPETET">
<PARAM name="type" value="application/x-java-applet;jpi-version=1.4.2">
<PARAM name="archive" value="Sipetet.jar,SIPETETclient.jar,Swsse.jar,Swebserviceclient+ssl.jar,BST.jks">
No Java 2 SDK, Standard Edition v 1.4.2_08 support for APPLET!!
</OBJECT>


And a "test form" with one button in it as follows.


<form name="form2" action="">
<input type="submit" value="TestIt!" name="SubmitButton"
onKlick="testApplet()">
</form>

Note that I had to spell the above Javascript event as onKlick to get this message posted on JavaRanch.

Here is my Javascript function

function testApplet()
{
returnStr = document.applets[0].testUserHandler();
alert(returnStr);
return null;
}

In my applet, the method "testUserHandler()" just returns a string.

This all seems to work well (i.e. I see the ALERT window pop up with the correct text), *EXCEPT* that my applet's init() method is called after every invocation of my Javascript function testApplet(). How do I set up my application so that the applet's method is called, but the init() method isn't called?

Thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That shouldn't happen. Are you sure you're not unintentionally calling the init() method from your applet code?
 
Lanny Gilbert
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm positive I'm not calling the init()) method.

And you're right, it shouldn't do that, which is why I'm asking if anyone else has seen this. If it helps, I'm using IE6.x as my browser.
 
Norm Radder
Bartender
Posts: 1526
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A WAG
Could it be that the browser is reloading the page after doing a "Submit" from a <form?
Try some tests by using a type=Button vs a type=submit and see what happens.
 
Lanny Gilbert
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was it! If you use input type="submit", then if you don't supply an action the current page is reloaded.

Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic