Connecting Tech Pros Worldwide Forums | Help | Site Map

document.write

Trevor Stapleton
Guest
 
Posts: n/a
#1: Jul 20 '05
can anyone tell me how to stop the document.write opening a new window
when called in a function, what I want to do is really simple but is
is defeating at every turn.
I have a line of text that is a link on an html page, when clicked i
want the the function called to print a name, imediatly after the
calling link (on the same page) please help whilst I still have some
hair left.

TIA
Trevor

Dennis M. Marks
Guest
 
Posts: n/a
#2: Jul 20 '05

re: document.write


I have read the following message from Trevor Stapleton
<trevor.stapleton@ntlworld.com>
and have decided to lend my vast knowledge.

The writer said:[color=blue]
> can anyone tell me how to stop the document.write opening a new window
> when called in a function, what I want to do is really simple but is
> is defeating at every turn.
> I have a line of text that is a link on an html page, when clicked i
> want the the function called to print a name, imediatly after the
> calling link (on the same page) please help whilst I still have some
> hair left.
>
> TIA
> Trevor
>[/color]

and my reply is:
A document.write done after the page has been displayed always replaces
the entire page including any scripts that were in the page. You will
need some other method such as a form or iFrame. You can also
dynamically replace a division using the innerHTML function but I have
not had much success with it.

--
Dennis M. Marks
http://www.dcs-chico.com/~denmarks/
Replace domain.invalid with dcsi.net


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
McKirahan
Guest
 
Posts: n/a
#3: Jul 20 '05

re: document.write


"Trevor Stapleton" <trevor.stapleton@ntlworld.com> wrote in message
news:is3i30pt6ev3v4iau064m2h6qh317bp04d@4ax.com...[color=blue]
> can anyone tell me how to stop the document.write opening a new window
> when called in a function, what I want to do is really simple but is
> is defeating at every turn.
> I have a line of text that is a link on an html page, when clicked i
> want the the function called to print a name, imediatly after the
> calling link (on the same page) please help whilst I still have some
> hair left.
>
> TIA
> Trevor[/color]

Consider the use of ".innerHTML":

<html>
<head>
<title>inner.htm</title>
<script type="text/javascript">
function inner() {
results.innerHTML = "<b>" + document.forms[0].text.value + "</b>";
}
</script>
</head>
<body onload="document.forms[0].text.focus()">
Type something and press "Enter".
<br>
<form>
<input type="text" name="text" onblur="inner()"> &nbsp;
<span id="results" />
</form>
</body>
</html>


Thomas Mlynarczyk
Guest
 
Posts: n/a
#4: Jul 20 '05

re: document.write


Also sprach Dennis M. Marks:
[color=blue]
> You will need some other method such as a form or iFrame. You can also
> dynamically replace a division using the innerHTML function but I have
> not had much success with it.[/color]

<a href="coolpage.html" onclick="addText(this); return false;">Click
here!</a>
<br>
<a href="coolpage.html" onclick="addText(this); return false;">And here!</a>

function addText(x) {
x.innerHTML += ' Ah, that feels good!';
}

This should work on modern browsers. The return false is just for testing -
it prevents "coolpage.html" from being loaded (thus disabling the link) -
but without it, you wouldn't see any result as coolpage would load
immediately.


Closed Thread