Page 1 of 1

Possible to retrieve properties/values from Java object?

Posted: Tue Oct 24, 2006 10:06 am
by Jenk
.. into a form, in 'realtime'?

Someone has asked me to look into the possibility of using a Java applet as a CAPTCHA, but to avoid submitting a form and/or new page request, so ideally they would like a generated value from the applet to be available 'realtime' for submission with the rest of the form, or is submitted as the resulting value..

Is this possible?

So the html would look something along the lines of:

Code: Select all

<html>
<body>
<script type="text/javascript">
function doStuff()
{
    var data = document.getElementById('applet').myAppletPropertyOrValue;
    //do something with data..
}
</script>
<form action="page.php" method="post" onSubmit="doStuff(); return false;">
<object name="MyJavaApplet" id="applet" code="MyApplet" />
<input type="submit" />
</form>

Posted: Tue Oct 24, 2006 10:14 am
by Luke
You can do it with javascript I'm pretty sure... let me look in my book and see if I can find anything for ya... hang on

Well, it says a few things about scripting with java, but it's a little over my head at the moment. It is possible (as far as i can tell) and it explains it as if you can just access the properties directly, but I think it must be a little more complicated than that.

Sorry i couldn't help ya.

Posted: Tue Oct 24, 2006 10:49 am
by RobertGonzalez
Yes, it can be done. The project I am working on now (in PHP) is being revamped from a Java project that did use this. How it did, I know not. But I know it can be done.

Posted: Tue Oct 24, 2006 11:21 am
by Jenk
Thanks guys, will keep burrowing. (could take a while.. "Java Object" tends to return just a few results :P)

So far I've ascertained you can force a submit with the applet, so that is a possible route.

Posted: Tue Oct 24, 2006 11:40 am
by Burrito
yes it can be done.

I have done something like this in the past:

Code: Select all

<script>
document.appletName.methodName(arg);
</script>

<applet code="someApplet.class" codebase="classes/" id="appletName" name="appletName">
obviously the methods need to be public

Posted: Tue Oct 24, 2006 1:43 pm
by Jenk
excellent, thank you!