Jump to content
xisto Community
Propeng

Problem With Javascript Alert();

Recommended Posts

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 by Propeng (see edit history)

Share this post


Link to post
Share on other sites

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

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

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

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 by Propeng (see edit history)

Share this post


Link to post
Share on other sites

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

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

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

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

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

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...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.