document.write

T

Trevor Stapleton

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
 
M

McKirahan

Trevor Stapleton said:
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

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>
 
T

Thomas Mlynarczyk

Also sprach Dennis M. Marks:
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.

<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.
 

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,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top