Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problrm in calling userdefined method in onclick event of button dynamically

 
Rakesh Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi dear all,

I am dynamically creating html page as
document.writeln("<input type=\"button\" id=\"btn\" value=\"Table\" onclick=\"alert('xxxxxxxxxx'); test();\" />")

Here alert is calling ,but teste() method is not calling.I observerd that if we call any library function like print(), alert() it will be called.Pronlem for only userdefined functions.


Sanmple code is below
-----------------------
<HTML>
<HEAD>
<TITLE> Applet Test </TITLE>
<SCRIPT LANGUAGE="JavaScript">

function graphdisplay()
{
alert("graphdisplay");


document.writeln("<input type=\"button\" id=\"btn\" value=\"Table\" onclick=\"alert('xxxxxxxxxx'); teste();\" />")

}

function test()
{
alert("teste---------------success")
}

</SCRIPT>
</HEAD>

<body onload="graphdisplay();">
<form id="inqform" name="inqform">
<script> </script>

</form>
</body>
</HTML>


Please respond ASAP if anybody have any solution very urgrnt.

thanks
rakesh
 
Henry Wong
author
Marshal
Pie
Posts: 21212
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the Java in general forum -- ie. a forum for Java questions. It would help if you asked the question in the correct forum.

Anyway, I'll move it to the Javascript forum for you...

Henry
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Well to start with this is Javascript and not java where you posted it.
So you are getting the first alert (xxxxxxxxxx)?


What is wrong with just putting the button on in html rather than constructing it in javascript?

Sean
 
Rakesh Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No ihave to dynamically switch between graph and table with one html.So i hav eto use document.write to create page.Please reply if you have any idea
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you CAN NOT use document.write AFTER the page loads.

Do a view source on the page. You will see that document.write REPLACES the ENTIRE document.

If you want to switch, you need to either have the content on the page already, you need to just show it with css [display: block/none] or you need to use DOM methods [createElement/appendChild/removeChild] OR you use innerHTML.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic