error calling function more than once within else

R

Red Ogden

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");
}

}
 
D

Dom Leonard

Red said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top