• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problrm in calling userdefined method in onclick event of button dynamically

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic