wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with passing info to applet" Watch "Problem with passing info to applet" New topic
Author

Problem with passing info to applet

Lawrence Keeney
Greenhorn

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);
add(output);
}
public void toCvm(String s)
{
output.setText(s);
}
}



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

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


Lawrence
Dirk Schreckmann
Sheriff

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]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with passing info to applet
 
Similar Threads
Problem with passing info to applet
Repost of Javascript problem with data transfer to applet.
Upload file using servlet
Java message on javascript alert
how to pass a value from an applet to a html field