Pass SQL command from Applet to JavaScript function

My last post recorded an important milestone for me, because I managed to call PHP code from a JavaScript function.

On an earlier occasion, I had managed to call a JavaScript function from an Applet.

My next task was to put the two together, and I did this in two steps the first of which (reported in the current post) was to adapt the previous Applet to JavaScript example to display an SQL command. This was essentially a cosmetic exercise, but it acted as a refresher on the code.

The only change to the Applet code was to replace "Hello World" with an SQL string. There is no need to reprint that here as it was given in my previous post on the topic.

In the HTML, I modified the table to display the Applet above the text box, and I widened them both. I also removed the update Applet function, as it was not required for the current exercise. It was then as follows:

<html>
<body>
<script type="text/javascript">
function updateWebPage(myArg)
{
document.getElementById("txt1").innerHTML=myArg;
}
</script>
<form>
<table border=0 align='center' cellpadding=0 cellspacing=0 >
<tr>
<td valign='top'>
<table>
<tr><td style='text-align:center; background-color:#EEEEEE'>Applet</td></tr>
<tr><td>
<applet code="JSHelloWorld2.class"
width="500" height="80" MAYSCRIPT style="border-width:0;" name="jsap" id="jsap">
</applet> </td></tr>
<tr><td style='text-align:center; background-color:#EEEEEE'>JavaScript</td></tr>
<tr><td><textarea style='width:500px; height:50px' name='txt1' id='txt1'>Query goes here</textarea></td></tr>
</table>
</form>
</body>
</html>

It came up initially as shown below:

After clicking the Applet button it was then as shown below:

And to my amazement, I could modify the text (see below) as many times as I liked, and the modified text was transferred across every time.

Comments

Popular posts from this blog

A few notes on JavaScript

Forum Comments on Java Applets

Creating a Custom Swing Component