luxeon Posted July 11, 2009 Share Posted July 11, 2009 Please help me... this code not working.. sorry i'm a beginner <html> <head> <title>java</title> <script type="text/javasript" src="script.js"> </script> </head> <body> <h1 id="text"> </h1> </body> </html> window.onload = writeM; function writeM() { document.getElementById("text").innerHTML = "hello"; } Link to comment https://forums.phpfreaks.com/topic/165591-solved-problem-with-easy-javascript-code/ Share on other sites More sharing options...
RichardRotterdam Posted July 11, 2009 Share Posted July 11, 2009 What's not working about it and does the script.js contain the js code: window.onload = writeM; function writeM() { document.getElementById("text").innerHTML = "hello"; } Link to comment https://forums.phpfreaks.com/topic/165591-solved-problem-with-easy-javascript-code/#findComment-873437 Share on other sites More sharing options...
BillyBoB Posted July 11, 2009 Share Posted July 11, 2009 Its fair to assume that the js is from the file mentioned above... but your error lies where you call the onload function. writeM by itself is a variable you are calling for a function. Try: window.onload = writeM(); function writeM() { document.getElementById("text").appendChild(document.createTextNode("hello")); } You should also look into DOM and the correct way to add text to an element. http://slayeroffice.com/articles/innerHTML_alternatives/ this is where i found the information. Very informative stuff for javascript. Link to comment https://forums.phpfreaks.com/topic/165591-solved-problem-with-easy-javascript-code/#findComment-873441 Share on other sites More sharing options...
luxeon Posted July 11, 2009 Author Share Posted July 11, 2009 Not work I did exactly as in video tutorial (tutorial use Mac, i use windows).. but I did not result... i think here is a simple answer... please help me next... the name of the firs script - script.html second - script.js Link to comment https://forums.phpfreaks.com/topic/165591-solved-problem-with-easy-javascript-code/#findComment-873446 Share on other sites More sharing options...
BillyBoB Posted July 11, 2009 Share Posted July 11, 2009 Actually my bad I typed something a bit wrong i think... try: window.onload = function() { writeM(); }; function writeM() { document.getElementById("text").appendChild(document.createTextNode("hello")); } Link to comment https://forums.phpfreaks.com/topic/165591-solved-problem-with-easy-javascript-code/#findComment-873453 Share on other sites More sharing options...
RichardRotterdam Posted July 11, 2009 Share Posted July 11, 2009 Your code is fine it's just a typo you made in your script tag you wrote text/javasript instead of text/javascript change : <script type="text/javasript" src="script.js"> to: <script type="text/javascript" src="script.js"> Link to comment https://forums.phpfreaks.com/topic/165591-solved-problem-with-easy-javascript-code/#findComment-873488 Share on other sites More sharing options...
luxeon Posted July 11, 2009 Author Share Posted July 11, 2009 :D :D thanks... Link to comment https://forums.phpfreaks.com/topic/165591-solved-problem-with-easy-javascript-code/#findComment-873563 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.