Loading...
Logo
Processing Forum
hi there

Is it possible to get data for a Processing applet from the URI of the page it is running on?

Basically, I have one Processing sketch that will need to have dozens of versions running concurrently, the only difference being some initial variables.  I want to have a single HTML page linking to the processing sketch, which then passes a user selection to the sketch; it seems the logical way to do this is with a pull-down menu form, which the Processing sketch uses to populate initial variables.

For example, if my Processing sketch is hosted at:


and I pass form data with the get method:


is there any way to use the variable "bar" in my sketch like this:

Copy code
  1. void setup() {
  2. int bar = intFromFormData;
  3. }

  4. println(bar);

  5. >>>100

any ideas?

Replies(4)

Not as is, but the URL information can be taken by a JavaScript program which can then pass it to the applet. The old forum as several examples of such communication.
ok, I guess I figured.

I've been trying to wrap my head around the param() function... is this on the right track?
It can be a way to do it, but still need JavaScript to put the data there.
yeah, I have no aversion to JavaScript.

If you know another way besides param(), I'm all ears... I can't seem to get it to work... currently following the param() example to the letter, as far as I can tell.

so the idea is to alter a parameter on the index.html file... just put a tag, e.g. <param name="back" value="51" /> in this page among the other applet parameters?  I open the page in my browser, and the parameter shows up in the source, but processing isn't seeing it.

[edit]
I figured it out.  Thanks PhiLho.

For future reference, I didn't realize the JS in the stock index.html page was causing the Java Applet to use the JS parameters instead of the <param> tags.  So, I think it will work if I include these variables in both the <param> tags and in the JS attributes hash.

[/edit]