Retrieve values from a Java applet for HTML form (CGI)Tag(s): Javascript interaction

Retrieve the value with a Javascript function called via the onSubmit event of the form.


public class InitHTMLForm extends java.applet.Applet {
   public String getFirstName() {
       // in real life, you have TextField in your Applet and
       // you want to transert its content to the HTML FORM
       // return myTextField.getText();
       return "Real's HowTo";

[HTML and Javascript]

function getValueFromApplet(){
   document.myForm.q.value = document.myApplet.getFirstName();
   return true;
 <APPLET CODE="InitHTMLForm.class" 
       HEIGHT=0 WIDTH=0>
     onSubmit="return getValueFromApplet()">
   <INPUT TYPE="hidden" VALUE="" NAME="q">
   <INPUT TYPE="submit" VALUE="Submit" >

Try it here

blog comments powered by Disqus