471,079 Members | 948 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,079 software developers and data experts.

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('layer1', '<i>1st new base field</i>');
write_layer('layer2', '<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(build){

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

}
}

function write_layer(thislayer, texttoadd)
{
if (document.layers) { // 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.getElementById) {

document.getElementById(thislayer).innerHTML = texttoadd;
}

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

}
Jul 20 '05 #1
1 2170
Red Ogden wrote:
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('layer1', '<i>1st new base field</i>');
write_layer('layer2', '<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.

<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

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Steve Richfield | last post: by
11 posts views Thread by suzy | last post: by
7 posts views Thread by jacob navia | last post: by
reply views Thread by erik.erikson | last post: by
47 posts views Thread by teju | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.