Jump to content

Error on fun call of a dynamic object


josekarun

Recommended Posts

When I click the button which I creted dynamically, its giving error, actully It should call Show() ? Would appriciate anybody can provide some help on this?<html><head><title> Dynamic Page</title><script type="text/javascript">function Show(){ alert("hi");}function testit(){ document.write("<input type="+"button"+" value="+"click me"+" onclick="+"Show()>" ) }</script></head><body><input type="Button" value="Click and see the wonder" onclick="testit()"></body></html>

Link to comment
Share on other sites

document.write writes the button to the new page, none of the current page then exists ie the function, what you need to do is pass the function in the document.write to this new page.document.write("<head><script>function Show(){alert('hi')}<\/script></head><input type="+"button"+" value="+"click me"+" onclick="+"Show()>" ) This works.

<html><head><title> Dynamic Page</title><script type="text/javascript">function Show(){alert("hi");}function testit(){document.write("<head><script>function Show(){alert('hi')}<\/script></head><input type="+"button"+" value="+"click me"+" onclick="+"Show()>" ) }</script></head><body><input type="Button" value="Click and see the wonder" onclick="testit()"></body></html> 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...