error calling function more than once within else

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Red Ogden

    error calling function more than once within else

    The following script returns an error saying document.all is null or
    not an object when I try to call the write_layer function more than
    once within the same else statement i.e.:

    else {
    write_layer('la yer1', '<i>1st new base field</i>');
    write_layer('la yer2', '<i>2nd new base field</i>');

    Id be grateful if anyone can advise me on how to get it to call
    multiple times inserting dynamic content in various <div> layers
    depending on the build variable value.

    Many thanks in advance
    Redge

    =============== script========= =============== =============
    function build_text(buil d){

    if (build=='CORP') {
    write_layer ('layer1', '<b>1st new corp field</b>');
    }
    else {
    write_layer('la yer1', '<i>1st new base field</i>');
    write_layer('la yer2', '<i>2nd new base field</i>');

    }
    }

    function write_layer(thi slayer, texttoadd)
    {
    if (document.layer s) { // for Netscape 4
    document[thislayer].document.open( ); // first you have to open
    the layer
    document[thislayer].document.write (texttoadd); // then you
    write to it
    document[thislayer].document.close (); // then you have to
    close it

    }
    else if (document.all) {
    document.all[thislayer].innerHTML = texttoadd; // with MSIE
    you can use innerHTML
    // document.all[thislayer].innerHTML += "texttoadd" ; // you can
    also append text to the current text in the layer"
    }

    else if (document.getEl ementById) {

    document.getEle mentById(thisla yer).innerHTML = texttoadd;
    }

    else {
    document.write( "Layers are not understood by the browser");
    }

    }
  • Dom Leonard

    #2
    Re: error calling function more than once within else

    Red Ogden wrote:[color=blue]
    > The following script returns an error saying document.all is null or
    > not an object when I try to call the write_layer function more than
    > once within the same else statement i.e.:
    >
    > else {
    > write_layer('la yer1', '<i>1st new base field</i>');
    > write_layer('la yer2', '<i>2nd new base field</i>');
    >
    > Id be grateful if anyone can advise me on how to get it to call
    > multiple times inserting dynamic content in various <div> layers
    > depending on the build variable value.
    >[/color]
    <SNIP>
    I was unable to reproduce the problem under IE6. Suggets you check that
    the 'layer2' DIV actually has and id value of 'layer2', and that it is
    defined before calling the build_text() function ... still coming down
    the wire won't do :)

    Cheers,
    Dom

    Comment

    Working...