Solved

Passing a value toJavaScript

Posted on 1998-08-10
4
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

732 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