| 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.
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Lawrence Keeney
Greenhorn
Joined: May 31, 2004
Posts: 17
|
|
Thanks Dirk, I have been working on this simple code all evening and can't get it to stop clearing the number out. Lawrence
|
 |
 |
|
|
subject: Problem with passing info to applet
|
|
|