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

Calling JavaScript in JSP on click of a button

Status
Not open for further replies.

ilarum

Programmer
Aug 25, 2003
13
DE
Hi,
I have JSP with an applet embedded in it. The applet has a method called test(). In the JSP I have button called test. Now I need to call the method test on the click of the button in the JSP.

The JSP code is as follows.

<html>
<head>
<script type = &quot;text/javascript&quot; language = &quot;javascript&quot;>
function testing()
{
alert(&quot;Hello&quot;);
}
</script>
</head>
<body>
<form name = &quot;testing&quot;>
<input type = &quot;submit&quot; value = &quot;test&quot; onclick = &quot;testing()&quot;>
<applet
codebase = &quot; code = &quot;Testing&quot;
name = &quot;TestApplet&quot;
width = &quot;200&quot;
height = &quot;200&quot;
hspace = &quot;10&quot;
vspace = &quot;10&quot;
align = &quot;bottom&quot;
>


</form>
</body>
</html>

The Applet code is as follows

public class Testing extends Applet
{
String msg;
public void init()
{
setBackground(Color.cyan);
setForeground(Color.red);
msg = &quot;Inside Init() --&quot;;

}

public void start()
{
msg += &quot; Inside Start() --&quot;;
}

public void paint(Graphics g)
{
msg += &quot;Inside Paint(). &quot;;
g.drawString(msg, 10, 30);
System.out.println(&quot;Paint &quot;);
}

public void test()
{
System.out.println(&quot;Working&quot;);

}
}
 
add this to your script

<script type = &quot;text/javascript&quot; language = &quot;javascript&quot;>
function testing()
{
alert(&quot;Hello&quot;);
document.TestApplet.test();

}
</script>


-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top