File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Problem with passing info to applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with passing info to applet" Watch "Problem with passing info to applet" New topic

Problem with passing info to applet

Lawrence Keeney

Joined: May 31, 2004
Posts: 17
I generated the following code in order to transfer data between Javascript and an Applet. However when I do the transfer, the transferred information flashes on the screen and then is erased. I haven't been able to figure out what part of the code is erasing the data.

Can anyone help me?

I am obviously new to Java programming.

import java.applet.*;
import java.awt.*;

public class Transfer extends Applet {
TextField output;
String str = new String("");

public void init()
output = new TextField(4);
public void toCvm(String s)

<title>Data Transfer Test</title>
<!--Test of data transfer between javascript and an applet.-->
<script language="javascript" type="text/javascript">
function xfer(cell)
<body bgcolor="white">
Enter the number to be transferred to the applet...
<form method="post" onSubmit="return xfer(this)">
Enter Number: <input type="text" size="4" name="number">
<input type="submit" value="Submit">

<applet code="Transfer.class" width="60" height="35" name="dataXfer">

Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, Lawrence!

When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand.

When you submit the form, the page is being reloaded. That also reloads the Applet, which then includes a new blank TextField.

Offhand, I'm not sure how to make this suggested change, but I'd bet somehow the html can be changed to not submit the form to the server, and have the JavaScript handle it instead.

I'm moving this to the HTML and JavaScript forum, as I believe that the solution you're looking for isn't a Java-based one, but JavaScript-based instead.
[ May 31, 2004: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Problem with passing info to applet
It's not a secret anymore!