...

View Full Version : Prevent My Content From Disappearing



hiyatran
09-16-2011, 05:12 PM
How do I prevent my Link from disappearing??
When I click on the link, "Click Here"

It display, "Look At Me!!" but the link, "Click Here" is GONE
Is there a way to keep my link, "Click Here" from disappearing?
So when I click on the link, "Click Here" the content, "Look At Me!!"should display as well.

thanks


Here are my codes

<html>
<head>

<script type="text/javascript">
function display() {
document.writeln("Look At Me!!");
}
</script>
</head>

<body>
<a href="google.com" onClick="display()">Click Here</a>
</body>

</html>

Old Pedant
09-16-2011, 05:26 PM
Once a page is completely loaded, *ANY* calls to document.write will *WIPE OUT ALL THE CONTENTS* of that page, including even the JavaScript that did the document.write.

The *ONLY* time you can successfully use document.write is during the initial creation of a page.

You need to learn about DOM methods.

Many many many ways to do this.

*ONE* possible way:


<html>
<head>

<script type="text/javascript">
function display() {
document.getElementById("displayGoesHere").innerHTML = "Look At Me!!";
}
</script>
</head>

<body>
<a href="google.com" onClick="display()">Click Here</a>
<div id="displayGoesHere"></div>
</body>
</html>

But that's just one of many.

hiyatran
09-17-2011, 03:37 PM
.innerHTML is used when you trigger an event but if you just want to display the text how would you go about do it??
I don't want to used document.writeln because it will "Wipe out all the contents" of that page.
So I have some HTML text and javascript text. I would like both to display on my page.

Here's my code


<html>
<head>

<script type="text/javascript">
function display() {
document.writeln("How do I make both text appear");
}
</script>
</head>

<body onload="display()">
I would like this text in the body to remain.

<script type="text/javascript">
display();
</script>


</body>
</html>
thanks

xelawho
09-17-2011, 03:48 PM
<html>
<head>

<script type="text/javascript">
function display() {
document.getElementById("displayGoesHere").innerHTML = "Look At Me!!";
}
</script>
</head>

<body>
<a href="javascript:void 0" onClick="display(); return false";>Click Here</a>
<div>I would like this text in the body to remain.</div>
<div id="displayGoesHere"></div>
</body>
</html>

hiyatran
09-17-2011, 03:59 PM
<a href onclick="display(); return false";>Click Here</a>

If I was to take this part of the code out this will not work but how can I make it work without the Click Here link

xelawho
09-17-2011, 04:05 PM
:confused:

you need something to fire the display() function or your text will not show.

you could fire it when the document loads, but that would be kind of pointless - you might as well just write it directly in like the "I would like this text in the body to remain" text.

there's any number of ways that a user can fire a function (and in this case show the text) - buttons, checkboxes, radio buttons, etc, plus some others involving timers and event listeners.

it all depends on what you want to do...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum