Applet. is not a function
I have the following HTML:
public class HelloApplet extends Applet
{
java.awt.TextField firstName;
public void start()
{
Label d = new Label("Sample java.awt.applet demo");
Label l = new Label("FirstName:");
firstName = new TextField(20);
setFirstName("TestString");
Button btn = new Button("Submit");
add(d);
add(l);
add(firstName);
add(btn);
}
public void setFirstName(String name)
{
System.out.println("SetTheName called");
firstName.setText(name);
}
}
And the following HTML:
.<Html>
<head>
<title>A Sample Applet</title>
<script>
function setName()
{
var obj = document.getElementById("myapplet");
alert("OBJ IS " + obj);
setTimeout(function(){obj.setFirstName("TheFirstName");},1000);
}
</script>
</head>
<body>
<input type="button" value="Enter Name" onClick="set()"/>
<applet code="com.prakash.HelloApplet" id="myapplet" width=500
height=400 MAYSCRIPT></applet>
When I press the html button'Enter Name' ,I get following in the console:
Error: TypeError: obj.setFirstName is not a function
The obj is not null and it is of correct type (checked through alert). I
tried with and w/o the setTimeout but does not help. Am I doing something
wrong? (The page is served through tomcat) -Thanks
No comments:
Post a Comment