Propeng 0 Report post Posted September 24, 2007 (edited) Hi Everyone, i just need to know that this javascript code is formatted correctly: (A piece of code that it's written BESIDE an HTML code.) <body onLoad="alert('My Text Here');">My body contents</body> |||Always keeps telling me that this was incorrect. Edited September 24, 2007 by Propeng (see edit history) Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted September 24, 2007 Hmm, it seems to works on my side. I tested the simple code in FF2 and IE6. Of cause i added the standard HTML tags of <html></html> But even without that also it still works. Generally, if you want to do that, it's recommended you group all your function in a script section like this<script language="javascript" type="text/javascript">function myOnLoad(){ alert('My Text Here');}</script>You're recommended to put it in within the header section, before the body. Then change your body onload to <body onLoad="myOnLoad();">My body contents<body> That way, it's easier for your to maintain your code next time. All your code should reside at one place. If you have even more code, you can use external javascript file. This can help you organize your code into different file per category or group. At the same time, it allow easy reuse of code throughout your entire project, or even across project.<script src="./yourjavascriptfile.js" language="javascript" type="text/javascript"></script> Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted September 25, 2007 Hi Everyone, i just need to know that this javascript code is formatted correctly: (A piece of code that it's written BESIDE an HTML code.) <body onLoad="alert('My Text Here');">My body contents</body> |||Always keeps telling me that this was incorrect. Very strange situation, i just copy/paste your code and test it without errors, works fine, with which browser do you test your code? Best regards, Share this post Link to post Share on other sites
Sten 0 Report post Posted September 25, 2007 i would normally do it like faulty.lee said, put it in the head on just make alert() onload.i just tried yours though and it works. Share this post Link to post Share on other sites
Propeng 0 Report post Posted September 25, 2007 (edited) Very strange situation, i just copy/paste your code and test it without errors, works fine, with which browser do you test your code? Best regards I'm using Firefox 2 on Windows (The first time i tested it, it was working fine.). Edited September 25, 2007 by Propeng (see edit history) Share this post Link to post Share on other sites
kelvinmaki 0 Report post Posted September 25, 2007 Hi Everyone, i just need to know that this javascript code is formatted correctly: (A piece of code that it's written BESIDE an HTML code.) <body onLoad="alert('My Text Here');">My body contents</body> |||Always keeps telling me that this was incorrect. It should work for the above code, however for my experience, when I'm using javascript, some browser like IE6 couldn't load it. So when dealing with Javascript, I would always put a 'java script:' in front. <body onLoad="java script:alert('My Text Here');">My body contents</body> You encounter that problem might be due to this. Might be. Just some info since FF2 is working. Share this post Link to post Share on other sites
iGuest 3 Report post Posted September 26, 2007 Hi Everyone, i just need to know that this javascript code is formatted correctly: (A piece of code that it's written BESIDE an HTML code.) <body onLoad="alert('My Text Here');">My body contents</body> |||Always keeps telling me that this was incorrect. Firstly, did you put all this inside HTML tags? If you didn't, then do so. Next, check the text inside the alert. Make sure there are no ' symbols, apart from the ones at the start and end. If it still doesn't work, try window.alert instead of alert. This shouldn't make a difference, but it's worth a try. If that doesn't work, check your browser is JavaScript compatible, and JavaScript is enabled. You should be able to enable it in your browser's settings, and if you have an old browser, I recommend downloading the latest version of Mozilla Firefox. If none of this works, try your script in forefox, then once the page has loaded, Open the Error Console (Tools -> Error Console). There may be an error in here, if there is, tell me, and it'll make it easier to fix. Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted September 27, 2007 Firstly, did you put all this inside HTML tags? If you didn't, then do so. Next, check the text inside the alert. Make sure there are no ' symbols, apart from the ones at the start and end. If it still doesn't work, try window.alert instead of alert. This shouldn't make a difference, but it's worth a try. If that doesn't work, check your browser is JavaScript compatible, and JavaScript is enabled. You should be able to enable it in your browser's settings, and if you have an old browser, I recommend downloading the latest version of Mozilla Firefox. If none of this works, try your script in forefox, then once the page has loaded, Open the Error Console (Tools -> Error Console). There may be an error in here, if there is, tell me, and it'll make it easier to fix. Well as i said in my previous post this is a very strange situation, i just test it again an works fine even without the HTML tags, i test it with Internet Explorer 6, Mozilla Firefox 2.0.0.6 and Opera 9.22, in all of them the javascript Alert() function runs correctly. Best regards, Share this post Link to post Share on other sites
iGuest 3 Report post Posted September 27, 2007 Well as i said in my previous post this is a very strange situation, i just test it again an works fine even without the HTML tags, i test it with Internet Explorer 6, Mozilla Firefox 2.0.0.6 and Opera 9.22, in all of them the javascript Alert() function runs correctly.Best regards, Yes, it sounds to me like it's a problem with Prepeng's browser. it's either outdated or has JavaScript disabled. Share this post Link to post Share on other sites
kelvinmaki 0 Report post Posted September 27, 2007 Yes, it sounds to me like it's a problem with Prepeng's browser. it's either outdated or has JavaScript disabled.You've just reminded me of an incident that happen to me once. Was trying to implement lightbox to my gallery with all those flashing and poping of images. However in Firefox, it work perfectly. But for IE, it just doesn't seems to popup those images. Definitely not coding problem as those are demos from the offically Lightbox site. Later found that its due to Trojan in my computer that totally disabled my Javascript. Even tried to enable it but still can't work. Anyway do a scan and clean, it might solve the problem without changing any coding. Cheers Share this post Link to post Share on other sites