Problem With Javascript Alert();

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > JavaScript

Problem With Javascript Alert();

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

Reply

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

 

 

 


Reply

TavoxPeru
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,

Reply

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



Reply

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

Reply

kelvinmaki
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

Reply

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

Reply

TavoxPeru
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,

Reply

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

Reply

kelvinmaki
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

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : javascript

  1. I Need Help With Javascript. - help plz (7)
    Well, I want to learn to code in JavaScript, but when I try to view the page in Firefox, it
    dosen't work. Can anyone tell me why its not working? Do i need to use a different browser?...
  2. Include Function For Javascript - (7)
    I've been working on an include function for javascript. It works just fine in Firefox and IE,
    but for some reason, it doesn't result in the loading of the scripts for Safari. The code is as
    follows: CODE function include(url) {   // Include Guard   var scripts =
    document.getElementsByTagName("script");   for (var index = 0; index <
    scripts.length; ++index) {     if (scripts.src == url) {       return;     }   }      //
    Inclusion   var head = document.getElementsByTagName("head").item(0);   ...
  3. JavaScript Frames & Querystring - (4)
    Hi, I actually want to create a HTML page which has the capablity of reading a QueryString
    (x.html?querystring=test) and then using a hidden frame pass on the data to an ASP Script on another
    server. For obtaining the QueryString i use the following:- CODE <script> function
    getQueryVariable(variable) {   var query = window.location.search.substring(1);
      var vars = query.split("&");   for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");     if (pair[0] == variabl...
  4. Best Way To Learn Javascript - I would very much like to know. (9)
    Well, I know HTML, I know CSS, so the next step is learning Javascript. I have heard that it is sort
    of an easier way to do things than PHP, though I would very much like to learn PHP as well. So, I
    thought that if I learnt Javascript, I might find it easier to learn PHP when I get to that point.
    The problem though is actually finding out the best way to learn Javascript. I have been to
    websites and things, but every time I read through the tutorials and articles and things, I
    didn't learn anything. It when in one ear and out the other, you could say. So, that is wh...
  5. Create And Import JavaScript Modules For A Large Script - (2)
    I have one main script which defines an object. I then have several other script files that define
    functions for that object. I have tried using the following setup to import the functions: HTML
    code snippet: <script type="text/javascript" src="/foo/mainbar.js"> <script
    type="text/javascript" src="/foo/modulebar.js"> Javascript code snippet: import
    Object.functionName; This works fine for Mozilla Firefox, but causes an error in Internet Explorer
    which causes the object to be undefined. I would like to know how better to import the functions
    into the m...
  6. Ever Needs To Find Out A Table Height Or With With JavaScript - Well stop looking, here is the answer (CSS and JS) (2)
    Welcome everybody to this litle tutorial. by v.DragonEyE.n09 Introduction: Using
    javascript you can find the height and width of a table, cell, div, image, etc.. the more simple way
    is to ask for this... QUOTE id= "myElement" border= "0" cellpadding=
    "0" cellspacing= "0" style= " height : 300px ; width
    : 450px ; " > some
    fake text and images for the example some fak...
  7. Getting Screen Resolution using Javascript. - (8)
    Is it possible to get the screen resolution of the users moniter using only javascript. No other
    external stuff, just pure javascript. I guess most of the people using JAVA for this. I also got
    some scripts regarding this which used SCREEN.WIDTH function or something, but they did not seem to
    work out. Any possible solutions. BTW, is it possible to get the resolution using PHP ( I guess it
    is not ) ......
  8. How To Create A Popup Window With Javascript? - (19)
    Please help me! I want to in popup massage suggest to visitors of my site to make my site their
    home page . Please note that I have some script code that visitors most click on a text to make my
    site their home page . Every one that can help me please send an email to soleimanian@noavar.com...
  9. javascript vs java - (12)
    in my opinion javascript is better then java becasue java requires more programing experecense
    then javascript and i think to that javascript is more reliable then java in some ways...
  10. Javascript: Disable Mouse Right-click In Browser - (16)
    just copy and paste this on to your html site in the head tag CODE <script
    language="JavaScript"> <!-- /* */ var message="Hey YOU!\nStop
    Stealing my pictures or\nFACE THE PUNISHMENT!" function click(e) { if
    (document.all) { if (event.button == 2) { alert(message); return false; } }
    if (document.layers) { if (e.which == 3) { alert(message); return false; } }
    } if (document.layers) { document.captureEvents(Event.MOUSEDOWN); } document.onmouse...
  11. Add Text To Textarea - I suppose it uses DOM and JavaScript?? (6)
    I am working on a web "application" thing that allows you to click a button to add text to a
    textarea. Similar to this forum when you click the BOLD button and it puts in {b}{/b} with the
    square brackets. I want a similar function like that. Also, I want it to add wherever the cursor is,
    not at the end. And after adding the thing, the cursor should be in between the tag or whatever that
    was added. All the extra stuff are extra priorities. For now I would like to get something that
    inserts text on click. The thing I came up with is: HTML html > head > <script ...
  12. Javascript Changes Aren't Working. - (6)
  13. JavaScript: Hide And Show Any Element With CSS - From the simple way to the more advanced way (Javascript & CSS) (5)
    Welcome everyone, this is my first post. The first thing you need to know is... CSS
    has two special attributes, the first one is " display " and the second is " visibility ". The
    difference between these two goes like this. " display ": has many properties or values, but the
    ones we need are "none" and "block". "none" is like a hide value, and "block" is like show. If you
    use the "none" value you will totally hide what ever html tag you have applied this css style. If
    you use "block" you will see the html tag and it's content. very simple. " visibi...
  14. Javascript Help Needed : Alert(z) Works Fine But Document.write Not - please (2)
    hi all, I am facing problem in my javascript, any kind of help would be apreciated CODE
    function basicFiles(){ //var Z = "";             for (i = 0; i <
    document.Form.regionlist.options.length; i++) {                 var x =
    document.Form.regionlist.options[i].value;                 var y =
    document.Form.regionlist.options[i].text;                 var Z =  "regions" +
    "[" + x + "]" + " = " + y + ", ";
                    alert(Z);             }                   } th...
  15. Fun With Javascript And Forms - Lets have some fun with javascript! (2)
    I will post here every week with new and exciting things to do in javascript! After i finish 10
    of them , ill do Ajax(real-time) - 1.Alerting and documenting Forms Ever seen those dynamic sites
    where if you hove your mouse or type something bad..etc , it popups up or dynamically gets written
    onto the page? Well i am here to teach or rather help with all that stuff! Step 1:Get notepad
    out and make a form CODE <form name='test'> <input type='text'
    name='field1'> Text displays here: <div id='r'> &...
  16. Javascript: Text To Texbox And Back To Text - (2)
    i need some help i want to create a thing where when some one double clicks a certain text it
    changes into a texbox where they can edit the text and the they double click and it changes into the
    test they just typed in. I have found this function in javascript that does some of it but i needs
    to be simplified CODE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html> <head> <title>Span to Text Box - Demo - DOM</title> <scr...
  17. Javascript: How Do I Create Embedded Pop-up Windows? - (7)
    The post title summarises my query - how do I create pop-up windows that are embedded inside a page?
    Broadly, there are two kinds of JavaScript pop-ups.. one is that ultra annoying one, which pops
    out a new instance of a browser window and displays something there (usually an ad) - made infamous
    by all the warez and porn sites. Second one, which has come to be quite well-known of late is the
    kind you see in recent versions of WordPress (in the Visual Editor) as well as LightBox based
    galleries. Here a small window (or rather a div) pops-up embedded in the middle of t...
  18. Javascript: Simple Slidedown Menu - Simple Slidedown Menu (2)
    This is a simple slidedown from the top menu. It can be placed on the Webpage as is. To modify it
    to a slideout menu, simply change the style and postion of the menu....
  19. Javascript Question - Vertical Scroll Box (4)
    Alright well I've been working and modifying this template for about a year now I think and
    I've started used JavaScript in it (bad to use templates I know, but I can't design them
    x_x). So I'm trying to put a vertical scroll box in my side events panel to save space, but it
    won't recognize the script. It takes the horizontal one I have as you can see if you look at
    the site, but not the vertical. Actually it won't take anything in that little panel. So my
    question really is, what could cause a javascript code to not work on a certain webpage ...
  20. Problems With Dynamically Loading Javascript - As well as dynamically inserting HTML (2)
    Hello, I have started to try to create a JavaScript application (or rather, AJAX, but the
    JavaScript is the part I'm having trouble with). I have come across a roadblock, though. I try
    to load an external JavaScript file by editing the innerHTML of a div tag to contain <script
    src="URL" type="text/javascript"> (with a real URL). The problem is that it is not loading. I have
    used FireBug to check the dynamic HTML status, I get the following (with code removed): CODE
    <html> <head/> <body> <div id="status"/> <div id=...
  21. JavaScript Off Redirect Script - How to redirect a browser when Javascrip (2)
    Hi, here's a trick that will redirect a browser when JavaScript is turned off. Why not redirect
    the ones that have JavaScript? It's because less than 10% of browsers have JavaScript turned
    off; therefore, is better to redirect less than 10% of visitors than over 90%. Simply paste this
    code into the HEAD section of your HTML document. CODE <script
    type="text/javascript"> <!-- /* Created by: Will Bontrager ::
    http://www.willmaster.com/ */ <noscript> <meta http-equiv="refresh"
    content="0; URL=ht...
  22. Vertical Marquee Using JavaScript - by The JavaScript Source (0)
    Hi, i find this script and hope that will be useful for somebody. Text scrolls from bottom to top,
    pauses, then scrolls up and out of view. A link can be added, opening in a new window. Configuration
    is simple. First copy the following code in a new file and name it vertical.js CODE /* This
    script and many more are available free online at The JavaScript Source ::
    http://javascript.internet.com Created by: Mike Hudson ::
    http://www.afrozeus.com */ /* To change the values in the setupLinks function below. You will
    notice there are two arr...
  23. Dynamicdrive: Good Site For JavaScript Codes - (5)
    If anyone needs Javascript codes or similar items for their web page a great place to go is
    http://www.dynamicdrive.com . They have hundreds of codes that are good. I would reccomend them for
    all your javascript needs....
  24. JavaScript: Simple Dropdown Menu - Simple Dropdown Menu (1)
    This simple dropdown menu is flexible enough to be used in various ways. It can be placed and
    modified in the webpage as is....
  25. Javascript: Browser Detection Script - Detect your visitors browser (0)
    If you want to detect your visitors browser, sebd them a message and redirect them use this script:
    CODE <script language="JavaScript"> <!-- var
    browserName=navigator.appName; if (browserName=="Netscape") { alert("Hi
    Netscape user!") window.location = "netscape.html" } else { if
    (browserName=="Microsoft Internet Explorer") {   alert("Hi Microsoft
    Internet Exlorer User!");   window.location = "MIE.html" }   else   {   
    alert("What are you...
  26. Calling Of Functions Between Mulitple External Javascript Files - How do I use an external script to call a function from another script (2)
    I have a page that requires many Javascript functions. In order to make the coding easier to read
    and edit, I decided to seperate them into 3 Javascript files. Two files will each do a specific job.
    One file will have the shared functions that both other 2 files will need to use. They are all
    linked to a page using three <script> tags. The difficult part is that after the page calls a
    function in one of the special code files, that Javascript file will need to call the functions
    located in the common Javascript file. The file will call several functions, and it will...
  27. Downloads With Javascript? - (7)
    Hi! I want to let people download .mp3's. But i don't want them tio have to right-click
    and "Save as". Is there a way with Java Script? Cheers!' Jens...
  28. Unobtrusive Javascript Image Rollovers - really cool & useful.. (0)
    i find this really cool..gr8 piece of code. image rollovers Create image rollovers for your
    navigation without hardcoding any JavaScript into the HTML code on your Web pages. Easy to
    implement, even for beginners, and works across all browsers. Degrades nicely for visitors with
    JavaScript turned off. CODE <!-- Paste this code into the CSS section of your HTML
    document  --> img {border: none;} ul {list-style-type:none;} ul li
    {display:inline;} <!-- Paste this code into an external JavaScript file named:
    rollover.js  --...
  29. Need Help With Javascript Form Validation - (2)
    Hello, I'm wondering if someone can help me with Javascript. I have created a form and the page
    in which the information submitted will be displayed (I will call these pages the form page and the
    submit page for easier reference). I want to know how to verify if a form is filled out correctly in
    the following manner: 1. Instead of placing the JavaScript form validation code on the form page, I
    want to add it on the submit page. 2. If there is an error from the filling out the form (i.e. the
    text field for "First Name:" was not entered), I want to display an error...
  30. Javascript: Help With Fetching Data From Webpages - (6)
    Hi guys, Am trying to come up with a Javascript function that can load a given URL and fetch
    part/whole of the web page and hand it over to my parser. Any ideas on how to do it ? One way I
    figured is to use XMLHttpRequest - but you need the server-end to respond by sending the required
    data to you in XML format. What if the page I want to extract data from is just an ordinary static
    page ... say I know the required data is a word that can be found at second paragraph of a page.. So
    how do I go about getting that page and extracting that info. Any help will be much...



Looking for problem, javascript, alert,

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for problem, javascript, alert,
I Need Help
With
Javascript.
help plz
Include
Function For
Javascript
JavaScript
Frames &
Querystring
Best Way To
Learn
Javascript I
would very
much like to
know.
Create And
Import
JavaScript
Modules For
A Large
Script
Ever Needs
To Find Out
A Table
Height Or
With With
JavaScript
Well stop
looking,
here is the
answer (CSS
and JS)
Getting
Screen
Resolution
using
Javascript.
How To
Create A
Popup Window
With
Javascript?
javascript
vs java
Javascript:
Disable
Mouse
Right-click
In Browser
Add Text To
Textarea I
suppose it
uses DOM and
JavaScript??
Javascript
Changes
Aren't
Working.
JavaScript:
Hide And
Show Any
Element With
CSS From the
simple way
to the more
advanced way
(Javascript
& CSS)
Javascript
Help Needed
: Alert(z)
Works Fine
But
Document.wri
te Not
please
Fun With
Javascript
And Forms
Lets have
some fun
with
javascript&#
33;
Javascript:
Text To
Texbox And
Back To Text
Javascript:
How Do I
Create
Embedded
Pop-up
Windows?
Javascript:
Simple
Slidedown
Menu Simple
Slidedown
Menu
Javascript
Question
Vertical
Scroll Box
Problems
With
Dynamically
Loading
Javascript
As well as
dynamically
inserting
HTML
JavaScript
Off Redirect
Script How
to redirect
a browser
when
Javascrip
Vertical
Marquee
Using
JavaScript
by The
JavaScript
Source
Dynamicdrive
: Good Site
For
JavaScript
Codes
JavaScript:
Simple
Dropdown
Menu Simple
Dropdown
Menu
Javascript:
Browser
Detection
Script
Detect your
visitors
browser
Calling Of
Functions
Between
Mulitple
External
Javascript
Files How do
I use an
external
script to
call a
function
from another
script
Downloads
With
Javascript?
Unobtrusive
Javascript
Image
Rollovers
really cool
&
useful..
Need Help
With
Javascript
Form
Validation
Javascript:
Help With
Fetching
Data From
Webpages
advertisement




Problem With Javascript Alert();



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE