my dog learned polymorphism*
The moose likes Applets and the fly likes pass parameter from text box to applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "pass parameter from text box to applet" Watch "pass parameter from text box to applet" New topic
Author

pass parameter from text box to applet

Rohit Agarwal
Greenhorn

Joined: Jul 13, 2001
Posts: 9
Gurus,
I need a help. In my requirement i have an applet to which i need to pass a parameter from the html page that it is embedded into.
Eg: say i have a text box in the html page in which the user enters a string. I need to pass this string (textbox value) into the applet as a parameter. How do i do that?
Basically it is applet - html communication.
Thanx in advance
Rohit
Alan Watts
Greenhorn

Joined: May 14, 2001
Posts: 28

Rohit,
You can do this with javascript I suppose, but have you considered doing it a slightly differently? Using a TextField in the applet you can read the value entered into the TextField as a String and then parse it if neccessary:
TextField Textfield;
String line = Textfield.getText();

Cheers
Alan
Rohit Agarwal
Greenhorn

Joined: Jul 13, 2001
Posts: 9
Hi Alan,
I know how to get the data from the Textfield object of an applet. What i want to know is that say if i have an applet which does not have an graphic content and i need to pass a value from an HTML text box to the applet. How can we do it.
Rohit
Karen Parker
Greenhorn

Joined: May 16, 2001
Posts: 15
You should be able to use the applet param tags to do this.
eg.

Then, in your applet class code, use getParameter to get the value of the string:

Now the only problem is getting the information from the HTML text field and putting it into the parameter tag. Perhaps you could use Javascript? Maybe someone else can suggest a solution to this part...
[This message has been edited by Karen Parker (edited July 23, 2001).]
Rohit Agarwal
Greenhorn

Joined: Jul 13, 2001
Posts: 9
Thanks Karen,
You are right, using the param tag i can pass values to Applet. As you pointed out the problem now is how to pass that value as a string to the value attribute of the param tag.
Can somebody throw some light on this. would appreciate it.
Rohit
Originally posted by Karen Parker:
[B]You should be able to use the applet param tags to do this.
eg.

Then, in your applet class code, use getParameter to get the value of the string:

Now the only problem is getting the information from the HTML text field and putting it into the parameter tag. Perhaps you could use Javascript? Maybe someone else can suggest a solution to this part...
[This message has been edited by Karen Parker (edited July 23, 2001).][/B]

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: pass parameter from text box to applet
 
Similar Threads
html+applet+servlet=how to do
passing a parameter back to my HTML page from my applet
Is it possible to pass a value from JSP to Javascript
passing variables to an applet from a html page
Passing String[] from jsp to applet