Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Data to Java Applet 3

Status
Not open for further replies.

Alastor

MIS
Aug 27, 1998
36
US
Is there a way to pass form data as a <PARAM> to a Java Applet? Code samples would be greatly appreciated.
 
Hi!<br>
This code may will help you:<br>
<br>
FormDataToApplet.html:<br>
**********************<br>
&lt;FORM onSubmit="return false"&gt;<br>
Please, give your name: <br>
&lt;INPUT TYPE="text" NAME="yourname" SIZE=40&gt;<br>
&lt;INPUT TYPE="submit" value="Pass data" onClick="<br>
document.FD.writeName(yourname.value);"&gt;<br>
&lt;/FORM&gt;<br>
&lt;HR&gt;<br>
&lt;APPLET CODE=FormDataToApplet.class NAME=FD height=100 width=200&gt;<br>
&lt;/APPLET&gt;<br>
<br>
FormDataToHtml.java:<br>
********************<br>
import java.applet.Applet;<br>
import java.awt.*;<br>
<br>
public class FormDataToApplet extends Applet {<br>
String name;<br>
<br>
public void init() {<br>
setBackground(Color.green);<br>
}<br>
<br>
public void paint(Graphics g) {<br>
if (name!=null) {<br>
g.setColor(Color.red);<br>
g.drawString("Hi, "+name, 10, 10);<br>
}<br>
}<br>
<br>
public void writeName(String s) {<br>
name=s;<br>
repaint();<br>
}<br>
}<br>
<br>
Good luck. Bye, Otto.
 
Okay Otto, this method works great with text boxes but I am having problems getting it to work with a combo box. I keep getting a null value result. However, when I submit the form using the post method it sends the correct data to the server. Can you help?
 
Here is some additional info: It seems to work fine under IE4 but not under Netscape.
 
Okay MIS :).<br>
The applet is the same, and here is the new html with a combo:<br>
**********<br>
&lt;FORM onSubmit="return false"&gt;<br>
Please, select a name: <br>
&lt;SELECT NAME="Combo"&gt;<br>
&lt;OPTION SELECTED&gt;MIS<br>
&lt;OPTION&gt;DigitalOx<br>
&lt;OPTION&gt;Otto&lt;/SELECT&gt;<br>
&lt;INPUT TYPE="submit" value="Pass data" onClick="<br>
document.FD.writeName(Combo[Combo.selectedIndex].text);"&gt;<br>
&lt;/FORM&gt;<br>
&lt;HR&gt;<br>
&lt;APPLET CODE=FormDataToApplet.class NAME=FD height=100 width=200&gt;<br>
&lt;/APPLET&gt;<br>
**********<br>
I try this with Netscape Communicator 4.5, and it works well.<br>
I have not got IE, but I hope that this code will good with, too.<br>
Good luck. Bye, Otto.<br>

 
Thanks Otto. That worked great. You're the king!
 
No, I am not; but thanks.<br>
Bye, Otto.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top