Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simplest Alert Script Ever

    This has got to be the simplest of all scripts, and yet it failed. This function is useless in webpages, really, I'm just trying to learn javascript from it. All I want it to do is alert "Silly rabbit, trix are for kids" except the word "Silly" is stored in a variable. Here's what I gots:

    function UselessFunction() {
    var Useless = 'Silly'
    alert( Useless + "rabbit, trix are for kids!" )
    }
    </SCRIPT><BODY onLoad="UselessFunction()">

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    I don't see any error in the function. Can you post the whole code?

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm with Glenn. The code looks correct other than the obvious missing opening <script> tag.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually there is a bug, you need a space after "Silly" or before "rabbit". Otherwise they'll run together as "Sillyrabbit" in the alert.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #5
    New Coder
    Join Date
    Jan 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But when I put it in my page it says Error in the status bar and no alert comes up at all

  • #6
    New to the CF scene
    Join Date
    Dec 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Single vs. Double Quotes

    I'm pretty sure the problem is that you use single quotes around 'Silly' and double quotes around "rabbit Trix..."

  • #7
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you download Mozilla (which is a MUCH better browser than IE anyways), ou can easily find the problem.

    Open the Mozilla web browser, load your page, then go up to the menu and choose: Tools > Web Development > JavaScript Console. It'll tell you exactly what the problem is. It's infinitely better than Internet Explorer's debugging.

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Single vs. Double Quotes

    Originally posted by Thermidor
    I'm pretty sure the problem is that you use single quotes around 'Silly' and double quotes around "rabbit Trix..."
    That has nothing to do with it.

    I also see that you're missing the </head> tag which should be between the </script> and the <body> tags. I tried your script in a simple page and it works so the problem is more likely elsewhere on your page. Post the whole page (or a link to it) if you can't find the problem.
    Last edited by Roy Sinclair; 01-07-2004 at 07:52 PM.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #9
    New Coder
    Join Date
    Jan 2004
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Your Problem

    Try this code.. It worked for me.. All I did was add the space after "Silly" and then put <script language....
    <html>
    <head>
    <title>...</title>
    <script language="JavaScript" type="">
    <!-- Begin
    function UselessFunction() {
    var Useless = 'Silly '
    alert( Useless + "rabbit, trix are for kids!" )
    }
    // END -->
    </SCRIPT>
    </head>
    <BODY onLoad="UselessFunction()">

  • #10
    Regular Coder
    Join Date
    Dec 2003
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well, all i can see is that at the end of the variable, and the alert, there is no ";". i know that when i miss that, the whole page is an error.

    thats all i see. its good to get in the habbit of putting one of the ";" at the end of every command even if you dont really need one.

    example

    function whatever(){
    var something = "silly"; //note the ";"
    alert(something+" rabbit, trix are for kids!"); // again the";"
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •