hi everybody.. i have this simple code: <html> <head> <script language="javascript" type="text/javascript"> document.write("<input type='button' value='push' onclick='hi()'/>"); function hi() { alert("hi"); document.write("<input type='button' value='enter' onclick='javascript: bye()'/>"); } function bye() { alert("bye"); } </script> </head> <body> </body> </html> if i try to run it on chrom its works well.. but on IE or FireFox its not define the bye() function.. whats the reason?! and how i can solve it?.. thanks very much..
nop.. still the same problem.. bye is not defined [TABLE] [TR] [TD][/TD] [TD] bye();[/TD] [/TR] [/TABLE]
bye is not defined onclick()onclickevent = click clientX=38, clientY=18 [TABLE] [TR] [TD][/TD] [TD] bye();[/TD] [/TR] [/TABLE]
Don't use document.write() in the <head> section of your documents. It will only cause problems. It's generally best to use DOM methods to create content on a page, but for this simple case, you could use: <!DOCTYPE html> <html> <head> <script language="javascript" type="text/javascript"> function hi() { alert("hi"); document.getElementById('myButton').onclick=bye; } function bye() { alert("bye"); document.getElementById('myButton').onclick=hi; } </script> </head> <body> <script language="javascript" type="text/javascript"> document.write("<input id='myButton' type='button' value='push' onclick='hi()'/>"); </script> </body> </html> Code (markup):