Solved

Passing a value toJavaScript

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Starting to learn JAVA, 7 59
Java Server Faces parameter pass? 6 37
ForLoop Example 3 40
table example 4 19
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

930 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