Null or not an object?? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Null or not an object??

CyGuyCyGuy Posts: 312Member
This is a simple problem, I have gotten it to work before, but now I am mysteriously having problems. It seems simple, and if I hadn't tried a hundred times, I wouldn't post. Pleaze help
[code]


welcome

var n="hello world";
document.all.displayScreen.innerHTML=n;






[/code]
I get the error in both browsers. I just can't see it.

Comments

  • zibadianzibadian Posts: 6,349Member
    : This is a simple problem, I have gotten it to work before, but now I am mysteriously having problems. It seems simple, and if I hadn't tried a hundred times, I wouldn't post. Pleaze help
    : [code]
    :
    :
    : welcome
    :
    : var n="hello world";
    : document.all.displayScreen.innerHTML=n;
    :
    :
    :
    :

    :
    :
    : [/code]
    : I get the error in both browsers. I just can't see it.
    :
    I cannot find the all property/method in the document object. See http://www.w3schools.com/htmldom/dom_obj_document.asp for the full reference.
  • BodkinBodkin Posts: 100Member
    You have 2 problems (maybe 3):

    0) Especially FF really likes you to use document.getElementById() in stead of document.all
    1) 'blue' does not work use blue or #0000FF or #00F in stead
    2) The script in the head is called before any tags appear in the document, hence DIV.innerHTML is not changed. I see two solutions to this:

    Solution 1:
    ----------
    Call a function in the header-script when the page has loaded

    [CODE][SIZE=2]


    welcome

    function showDisplayScreen() {
    var n = "hello world";
    document.getElementById("displayScreen").innerHTML = n;
    }






    [/SIZE][/CODE]


    Solution 2:
    ----------
    Move the SCRIPT-tags down below the DIV tags, NOT ABOVE!

    [CODE][SIZE=2]


    welcome




    var n = "hello world";
    document.getElementById("displayScreen").innerHTML = n;



    [/SIZE][/CODE]
  • CyGuyCyGuy Posts: 312Member
    many thanks. I really should get away from IE prop. Your solution is perfect.

    : You have 2 problems (maybe 3):
    :
    : 0) Especially FF really likes you to use document.getElementById() in stead of document.all
    : 1) 'blue' does not work use blue or #0000FF or #00F in stead
    : 2) The script in the head is called before any tags appear in the document, hence DIV.innerHTML is not changed. I see two solutions to this:
    :
    : Solution 1:
    : ----------
    : Call a function in the header-script when the page has loaded
    :
    : [CODE][SIZE=2]
    :
    :
    : welcome
    :
    : function showDisplayScreen() {
    : var n = "hello world";
    : document.getElementById("displayScreen").innerHTML = n;
    : }
    :
    :
    :
    :

    :
    :
    : [/SIZE][/CODE]
    :
    :
    : Solution 2:
    : ----------
    : Move the SCRIPT-tags down below the DIV tags, NOT ABOVE!
    :
    : [CODE][SIZE=2]
    :
    :
    : welcome
    :
    :
    :

    :
    : var n = "hello world";
    : document.getElementById("displayScreen").innerHTML = n;
    :
    :
    :
    : [/SIZE][/CODE]
    :

Sign In or Register to comment.