Passing parameter to applet using JavaScript


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Passing parameter to applet using JavaScript

  1. #1
    Nancy Guest

    Passing parameter to applet using JavaScript


    I am writing an application where I obtain data from one site, when I click
    a submit button I request another site to open. The second site contains
    an applet that contains a form. I want to put the data into the form. My
    JavaScript function to open the form and insert the data is called by the
    page onLoad event. The problem is that the applet isn’t finished initalizing
    before the showForm method is called. I get an “object does not exist” error,
    then the form opens (without my data). Here’s my function. Any help would
    be appreciated.

    <script language=”JavaScript”>
    function Selected() {
    var handyString = parent.location.search;
    var startOfSource = handyString.indexOf("acct=");
    if (startOfSource != -1){
    var result = handyString.substring(startOfSource+5,20);
    top.MapFrame.document.MapCafe.externalAPI("FindTool SetReqName Find \r\n");
    top.MapFrame.document.MapCafe.externalAPI("FindTool SetText \""+result+"\"");
    top.MapFrame.document.MapCafe.externalAPI("FindTool Show\r\n");
    }
    }
    </script></head>
    <BODY onload="Selected();">
    <APPLET………………



  2. #2
    Tom Duffy Guest

    Re: Passing parameter to applet using JavaScript


    Hello Nancy:

    It sounds to me like this is a problem more related to the stateless nature
    of HTTP. Here's one strategy off the top of my head:

    Write a cookie to the user's machine using JavaScript on your first page
    in the onUnload method. Then read the cookie on the next page in the same
    fashion and call document.write to write out the HTML for the page. In your
    document.write call, pass some parameters to the applet containing the data
    you need to pass to the applet. This assumes that your applet is configured
    to accept the parameters.

    In all honesty, you should consider a servlet so that you can get a hold
    of a session object to store the information (unless I've completely misunderstood
    the problem!).

    The obvious workaround, however, is to avoid the data transfer altogether
    and have the user enter data directly into your applet. If this is possible
    it might be the way to go.

    Tom Duffy

    "Nancy" <Nancy.Clauss@co.charlotte.fl.us> wrote:
    >
    >I am writing an application where I obtain data from one site, when I click
    >a submit button I request another site to open. The second site contains
    >an applet that contains a form. I want to put the data into the form.

    My
    >JavaScript function to open the form and insert the data is called by the
    >page onLoad event. The problem is that the applet isn’t finished initalizing
    >before the showForm method is called. I get an “object does not exist”

    error,
    >then the form opens (without my data). Here’s my function. Any help would
    >be appreciated.
    >
    ><script language=”JavaScript”>
    >function Selected() {
    > var handyString = parent.location.search;
    > var startOfSource = handyString.indexOf("acct=");
    > if (startOfSource != -1){
    > var result = handyString.substring(startOfSource+5,20);
    >top.MapFrame.document.MapCafe.externalAPI("FindTool SetReqName Find \r\n");
    > top.MapFrame.document.MapCafe.externalAPI("FindTool SetText \""+result+"\"");
    > top.MapFrame.document.MapCafe.externalAPI("FindTool Show\r\n");
    > }
    >}
    ></script></head>
    ><BODY onload="Selected();">
    ><APPLET………………
    >
    >



  3. #3
    John Timney (MVP) Guest

    Re: Passing parameter to applet using JavaScript

    You could also add some code to determine if the applet is loaded yet before
    doing anything else in the page, even better is to get it to call the
    javascript selected function from within the applet once it loads by marking
    the applet with the MAYSCRIPT tag to allow it to call javascript using the
    javascript:dofunction and getAppletContext method.

    Regards

    John Timney (MVP)

    checking if the applets loaded....

    <SCRIPT>
    function AppletReady(x) {
    return x.isActive();
    }
    </SCRIPT>

    <FORM>
    <INPUT TYPE=button
    VALUE="Check applet"
    onClick="if (!AppletReady(document.applets[0])) alert("not ready");" >
    </FORM>

    an example of calling Javascript from an applet.

    import java.applet.*;
    import java.net.*;

    public class inJava extends Applet{
    public void init(){
    String msg = "We will jump to an HTML tag";
    try {
    getAppletContext().showDocument
    (new URL("javascript:doAlert(\"" + msg +"\")"));
    getAppletContext().showDocument
    (new URL("javascript:jumpTo(\"#JUMP\")"));
    }
    catch (MalformedURLException me) { }
    }
    }

    [Javascript and HTML] <HTML><HEAD></HEAD><BODY>
    <SCRIPT>
    function doAlert(s) {
    alert(s);
    }
    function jumpTo(tag) {
    self.location=tag;
    }
    </SCRIPT>
    <APPLET CODE="inJava.class"
    NAME="myApplet" MAYSCRIPT
    HEIGHT=400 WIDTH=10>
    </APPLET>
    <P>
    <A NAME="JUMP">jump here from Java via Javascript</A>
    </BODY>
    </HTML>








Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center