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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with applet and ascii value returned as string

Status
Not open for further replies.

zwrley

Programmer
Aug 7, 2001
14
PH
I need help with calling a java applet using the <applet> tag and reading the value being returned by one of the functions in the class...

here's my code:

<html>
<script>
function doThis()
{
alert (document.applets[0].getData())
var tmp = document.applets[0].getData()
alert (tmp)
// some other codes here...
}
</script>
<body>
<form>
<applet code=&quot;acode.class&quot; archive=&quot;acode.jar&quot; width=150 height=25></applet>
<input type=&quot;button&quot; value=&quot;ok&quot; onClick=&quot;doThis()&quot;>
</form>
</body>
</html>

my question is how come whenever i do an alert, it shows me the value of document.applets[0].getData() but when i try assigning it to a variable and do an alert on the variable, it comes out empty.

I need to assign it to another variable because i can't do this directly document.writeln ('<param name=&quot;sample&quot; value=&quot;' + document.applets[0].getData() + '&quot;>'). The page will display an error message when it reaches this line so I tried assigning it to a variable &quot;tmp&quot; to do this line but i'm not getting the value. The getData() returns ascii %33%56%45%... as string, by the way.

Can anyone help me as to how to get this to work? Any help is greatly appreciated.

 
you can use unescape() to convert to plain text:

alert ( unescape( document.applets[0].getData() ) );


you could also write that var in the param like such...create a function:

function writeParam() {
document.write('<param name=&quot;sample&quot; value=&quot;' + document.applets[0].getData() + '&quot;>');
}

... and call it where you need:
<applet code=&quot;acode.class&quot; archive=&quot;acode.jar&quot; width=150 height=25>
<script type=&quot;text/javascript&quot;>writeParam();</script>
</applet>


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Thanks for the reply.

I've tried using the unescape() before but still nothing. Besides, i need the entire data retrieved from document.applets[0].getData() and do the document.write('<param name=&quot;sample&quot; value=&quot;' + document.applets[0].getData() + '&quot;>'). Can JSP make a difference? Will it be able to retrieve the actual data retrieved from document.applets[0].getData()?
 
>> Can JSP make a difference?
i'm not sure, but i doubt it since jsp is just another server side language and the applet is client side.

a better question would be &quot;is there another way to accomplish this without an applet?&quot;

what is the purpose of your applet?

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
We are using applet for security reason where the applet asks the user for a password and the call to getData() encrypts the password to be submitted to another application.

We thought of trying it in JSP since js couldn't recognize some of the special characters being passed by the encrypted data.

Any suggestions on how to go about this?

THANKS!
 
js has no problem with ascii codes like &quot;%33%56%45&quot;
alert(unescape(&quot;%33%56%45&quot;));
results in &quot;3VE&quot;

sounds like maybe there's a problem with the applet...

try this:
alert(typeof document.applets[0].getData());
you should get &quot;String&quot;

does this still not work?
var tmp = document.applets[0].getData();
alert (tmp);

perhaps you cannot call getData() twice...does this work properly?
alert (document.applets[0].getData());
alert (document.applets[0].getData());



=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
hi
THANKS A LOT!!
I got it working now! You were right, I can't make a call to the getData() twice, that's why was not getting the value.

THANKS!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top