Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.