Closed Thread
Results 1 to 8 of 8

Thread: Somethings not Working

  1. #1
    ImTheMessenger's Avatar
    ImTheMessenger is offline Learning Programmer
    Join Date
    Dec 2009
    Location
    Virginia
    Posts
    30
    Rep Power
    0

    Exclamation Somethings not Working

    Ok so i'm reading a book that's teaching me JavaScript & AJAX...
    and for all except 2 of the examples (or is one since the 2 scripts are needed together?) and basically it demonstrating how to use multi-level conditionals
    so here's the Html for the script
    Code:
    <!DOCTYPE htm_l PUBLIC "-/ / W_3C/ /DTD XHTML 1.0 Transitional/ / EN"
    					"h_t_tp://ww_w.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="ht_tp://w_ww.w3.org/1999/xhtml">
    <head>
    	<title>Switch/Case Handling</title>
    	<script type="text/javascript" src="\where i have my stuff\JavaScript\quotes.js"></script>
    </head>
    <body bgcolor="white">
    <h2>Famous Presidential Quotes</h2>
    <form action="#">
    	<input type="button" id="Lincoln" value="Lincoln" />
    	<input type="button" id="Kennedy" value="Kennedy" />
    	<input type="button" id="Nixon"
    value="Nixon" />
    </form>
    </body>
    </html>
    i looked over it word for word line by line and found no error...so i looked at the JavaScript
    ... ohh and i added some underscores so then the whole thing could be put up there... pesky links
    Code:
    window.onload = initAll;
    
    
    function initAll() {
    	document.getELementById("Lincoln").onclick = saySomething;
    	document.getElementById("Kennedy").onclick = saySomething;
    	document.getElementById("Nixon").onclick = saySomething;
    }
    
    
    
    function saySomething() {
    	switch(this.id) {
    		case "Lincoln":
    			alert("Four score and seven years ago...");
    			break;
    		case "Kennedy":
    			alert("Ask not what your country can do for you...");
    			break;
    		case"Nixon":
    			alert("I am not a crook!");
    			break;
    	default;
    	}
    }
    and found nothing amiss... well except for some typo's but i fixed those real quick... so i was wondering... does anyone know what the H#!! happened?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Somethings not Working

    getELementById("Lincoln")

    should be

    getElementById("Lincoln")
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    ImTheMessenger's Avatar
    ImTheMessenger is offline Learning Programmer
    Join Date
    Dec 2009
    Location
    Virginia
    Posts
    30
    Rep Power
    0

    Re: Somethings not Working

    ok i fixed that, however, i still get nothing since the scripts are designed to have a pop up message come up everytime i click one of the buttons... and i tried this on Opera,Firefox and IE8 and all them seem to get to the HTML but that's it nothing happens when i click them

  5. #4
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Somethings not Working

    You need an onClick event to call the JavaScript.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    DarkLordoftheMonkeys's Avatar
    DarkLordoftheMonkeys is offline Programming Professional
    Join Date
    Oct 2009
    Location
    Massachussets
    Posts
    255
    Blog Entries
    56
    Rep Power
    11

    Re: Somethings not Working

    I think it would be easier to directly include the event handlers in the HTML elements. That way you don't have to worry about what object this refers to.
    Life's too short to be cool. Be a nerd.

  7. #6
    ImTheMessenger's Avatar
    ImTheMessenger is offline Learning Programmer
    Join Date
    Dec 2009
    Location
    Virginia
    Posts
    30
    Rep Power
    0

    Re: Somethings not Working

    well thanks guys but for some reason none of my browsers will show thge codes i typed in + i found out that those 2 codes were "incomplete" and although i dopn't see what was different from my codes and the ones in the book... well i decided to download the script for the book from the site and just stared very hard at it decided my browsers were possessed since those codes worked perfectly well on my browser....

  8. #7
    Feral is offline Programmer
    Join Date
    Jul 2008
    Posts
    163
    Rep Power
    15

    Re: Somethings not Working

    Code:
    default;
    should be

    Code:
    default:
    the only other problem is what WingedPanther mentioned about getElementById

  9. #8
    semprance is offline Programmer
    Join Date
    Jan 2010
    Posts
    126
    Rep Power
    0

    Re: Somethings not Working

    Should:

    Code:
    document.getELementById("Lincoln").onclick = saySomething;
    Not be:

    Code:
    document.getELementById("Lincoln").onclick = "saySomething()";
    Not certain if the use of quotes/parentheses are a requirement or just a formality in javascript, but this is the way I've always done it.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Not working in FF/Chrome, working in IE
    By fedlerner in forum AJAX
    Replies: 17
    Last Post: 03-14-2011, 10:26 AM
  2. Working on C++
    By Beeko in forum C and C++
    Replies: 12
    Last Post: 08-06-2010, 04:16 AM
  3. CSS Not Working?
    By Volux in forum JavaScript and CSS
    Replies: 3
    Last Post: 06-08-2010, 10:34 AM
  4. Why isn't this working?
    By Osnarf in forum C and C++
    Replies: 2
    Last Post: 03-24-2010, 01:06 AM
  5. Not working
    By hbk in forum C and C++
    Replies: 2
    Last Post: 03-22-2010, 06:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

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