Solved

Passing a value toJavaScript

Posted on 1998-08-10
4
140 Views
Last Modified: 2010-04-16
I want to create a slider in java which can be used to pass a value to a javascript function located on the same page at the Applet.

Is this possible, and if so how.
0
Comment
Question by:RICHARDH
  • 3
4 Comments
 
LVL 28

Accepted Solution

by:
sybe earned 50 total points
ID: 1232256
I have just answered a similar question, so I'll repeat my answer here.


    sample code for the applet:
    ===========================
    import java.applet.*;
    import netscape.javascript.JSObject;

    public class JSObjectTest extends Applet {
       JSObject mozilla;
       String[] args;
       String msg;

       public void init() {
          msg = getParameter("msg");
          try {
             mozilla = JSObject.getWindow(this);
          }
          catch (NoClassDefFoundError e) {}

          String args[] = {msg + ""};
          try {
             mozilla.call("setVar", args);      
          }
          catch (NoClassDefFoundError e) {}
       }

    }

    =========================================

    sample code for HTML/Javascript:

    =========================================
    <HTML>
    <HEAD>
    <title>JSObjectTest.java</title>

    <script language="JavaScript">
    <!--
    function setVar(msg){
    alert(msg);
    }
    // -->
    </script>


    </HEAD>
    <BODY BGCOLOR="#FFFFFF">

    <applet name="jsobjecttest" code="JSObjectTest.class" width=2 height=2 MAYSCRIPT>
    <param name="msg" value="Your browser supports Java to JavaScript using the JSObject class">
    </applet>

    </BODY>
    </HTML>
    ======================================

    Note that the applet passes the parameter "msg" (in the applet tag) to the javascript function SetVar.

    That function is in this case an alert. But it could be anything like document.bgcolor, document.location etc.
0
 

Author Comment

by:RICHARDH
ID: 1232257
For the attention of sybe...
Many, many thanks for a very precise answer. I have one further question.

Where do I get the Netscape.javascript class which is imported into the Applet.

Thanks again
0
 
LVL 28

Expert Comment

by:sybe
ID: 1232258
If you have netscape (3+) installed, you should add the path to the netscape java classes into the CLASSLIB environment variable.

You can easily view the netscape classes by making a copy of it and renaming that copy to *.zip. Then you can open it using winzip.

If you have MSIE4 installed you will find it under one of the directories of C:\windows\java.

If you have found the right zip containing JSObject.class then add it to the CLASSLIB environmental variable:


something like:

CLASSLIB = C:\JDK\LIB\CLASSES.ZIP;C:\NETSCAPE\NAVIGATOR\PROGRAM\JAVA\CLASSES\java_30


0
 
LVL 28

Expert Comment

by:sybe
ID: 1232259
sorry, CLASSLIB should be CLASSPATH
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
hash value 2 39
mergeTwo  challenge 13 72
Issues installing SSL certificate into Apache Tomcat 3 70
mapAB Challlenge 35 89
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now