Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Problem With Javascript Alert();
Propeng
post Sep 24 2007, 08:47 PM
Post #1


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 11
Joined: 24-September 07
Member No.: 25,093



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.)
CODE
<body onLoad="alert('My Text Here');">My body contents</body>


|||Always keeps telling me that this was incorrect.

This post has been edited by Propeng: Sep 24 2007, 08:48 PM
Go to the top of the page
 
+Quote Post
faulty.lee
post Sep 24 2007, 10:04 PM
Post #2


Premium Member
Group Icon

Group: [HOSTED]
Posts: 495
Joined: 5-November 06
Member No.: 17,016



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
CODE
<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
CODE
<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
CODE
<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.
CODE
<script src="./yourjavascriptfile.js" language="javascript" type="text/javascript"></script>
Go to the top of the page
 
+Quote Post
TavoxPeru
post Sep 25 2007, 04:06 AM
Post #3


Super Member
Group Icon

Group: [HOSTED]
Posts: 763
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



QUOTE(Propeng @ Sep 24 2007, 03:47 PM) *
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.)
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,
Go to the top of the page
 
+Quote Post
Sten
post Sep 25 2007, 10:01 AM
Post #4


Oh come on Mrs. B!
Group Icon

Group: Members
Posts: 648
Joined: 6-June 07
From: Tasmania, Australia
Member No.: 22,422



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.


Go to the top of the page
 
+Quote Post
Propeng
post Sep 25 2007, 01:09 PM
Post #5


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 11
Joined: 24-September 07
Member No.: 25,093



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

This post has been edited by Propeng: Sep 25 2007, 01:17 PM
Go to the top of the page
 
+Quote Post
kelvinmaki
post Sep 25 2007, 01:24 PM
Post #6


Advanced Member
Group Icon

Group: Members
Posts: 170
Joined: 30-July 07
Member No.: 23,704



QUOTE(Propeng @ Sep 24 2007, 08:47 PM) *
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.)
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.

CODE
<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. wink.gif
Go to the top of the page
 
+Quote Post
Habble
post Sep 26 2007, 06:27 AM
Post #7


Premium Member
Group Icon

Group: [HOSTED]
Posts: 286
Joined: 17-June 07
From: Tasmania
Member No.: 22,699



QUOTE(Propeng @ Sep 24 2007, 08:47 PM) *
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.)
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.
Go to the top of the page
 
+Quote Post
TavoxPeru
post Sep 27 2007, 06:34 AM
Post #8


Super Member
Group Icon

Group: [HOSTED]
Posts: 763
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



QUOTE(Habble @ Sep 26 2007, 01:27 AM) *
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,
Go to the top of the page
 
+Quote Post
Habble
post Sep 27 2007, 08:15 AM
Post #9


Premium Member
Group Icon

Group: [HOSTED]
Posts: 286
Joined: 17-June 07
From: Tasmania
Member No.: 22,699



QUOTE(TavoxPeru @ Sep 27 2007, 06:34 AM) *
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.
Go to the top of the page
 
+Quote Post
kelvinmaki
post Sep 27 2007, 12:32 PM
Post #10


Advanced Member
Group Icon

Group: Members
Posts: 170
Joined: 30-July 07
Member No.: 23,704



QUOTE(Habble @ Sep 27 2007, 08:15 AM) *
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. mad.gif 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. dry.gif

Anyway do a scan and clean, it might solve the problem without changing any coding. Cheers
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Getting Screen Resolution using Javascript.(8)
  2. How To Create A Popup Window With Javascript?(19)
  3. javascript vs java(12)
  4. Javascript: Disable Mouse Right-click In Browser(16)
  5. Best Way To Learn Javascript(9)
  6. Javascript: Text To Texbox And Back To Text(2)
  7. Unobtrusive Javascript Image Rollovers(0)
  8. Dynamicdrive: Good Site For JavaScript Codes(5)
  9. Downloads With Javascript?(7)
  10. Javascript: Simple Slidedown Menu(2)
  11. JavaScript: Simple Dropdown Menu(1)
  12. Calling Of Functions Between Mulitple External Javascript Files(2)
  13. Javascript: Browser Detection Script(0)
  14. JavaScript: Hide And Show Any Element With CSS(5)
  15. Ever Needs To Find Out A Table Height Or With With JavaScript(2)
  1. Create And Import JavaScript Modules For A Large Script(2)
  2. Vertical Marquee Using JavaScript(0)
  3. JavaScript Frames & Querystring(4)
  4. JavaScript Off Redirect Script(2)
  5. I Need Help With Javascript.(7)
  6. Problems With Dynamically Loading Javascript(2)
  7. Add Text To Textarea(6)
  8. Javascript Question(4)
  9. Javascript: How Do I Create Embedded Pop-up Windows?(7)
  10. Include Function For Javascript(7)
  11. Fun With Javascript And Forms(2)
  12. Javascript Help Needed : Alert(z) Works Fine But Document.write Not(2)
  13. Javascript Changes Aren't Working.(6)


 



- Lo-Fi Version Time is now: 11th October 2008 - 06:28 PM