josekarun Posted May 10, 2006 Share Posted May 10, 2006 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 More sharing options...
scott100 Posted May 10, 2006 Share Posted May 10, 2006 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 More sharing options...
josekarun Posted May 10, 2006 Author Share Posted May 10, 2006 Oho scott thats solved my problem!!! Thanks a lot Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now