Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Layer question

Status
Not open for further replies.

michelledebeer

Programmer
Oct 26, 2001
22
0
0
SE
I have this function that prints a text to a layer without reloading the page.

function print_text(text)
{
if(document.layers)
{
with(document.layers['myLayer'])
{
document.open();
document.write(text);
document.close();
}
}
else
{
mylayer.innerHTML=text
}
}

I would like to extend this function so that I can specify what layer the text should be added to:

<a href=&quot;print_picture('image.gif','oneLayer');&quot;>click1</a>
<a href=&quot;print_picture('image.gif','anotherLayer');&quot;>click2</a>

The function starting like this:
function print_text(text,anyLayer) { ...

Where in the function do I do this?

Any thoughts?
// Michelle
 
function print_text(text, anyLayer)
{
if(document.layers)
{
with(document.layers[anyLayer])
{
. . .

anyLayer.innerHTML=text

 
No, that does not work...
I use IE 5.0

Here is the complete code:
<script>
function print_text(txt,anyLayer) {

if(document.layers)
{
with(document.layers[anyLayer])
{
document.open();
document.write(txt);
document.close();
}
}
else
{
anyLayer.innerHTML=txt // <-- Now there must be a layer named &quot;anyLayer&quot;
}
}
</script>


<a href=&quot;javascript:print_text('1texttettett', 'post1');&quot;>num 1</a><br>
<a href=&quot;javascript:print_text('2texttettett', 'post2');&quot;>num 2</a>
<div id=&quot;post1&quot; style='position:relative; left:0px; top:0px; height:100%px; width:100%px; visibility: visible'></div>
<div id=&quot;post2&quot; style='position:relative; left:0px; top:0px; height:100%px; width:100%px; visibility: visible'></div>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top