Solved

Passing a value toJavaScript

Posted on 1998-08-10
4
181 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

688 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