SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: document.write()
Hybrid View
-
Oct 28, 2003, 19:34 #1
- Join Date
- Jan 2003
- Location
- USA
- Posts
- 66
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
document.write()
i am trying to call a method that does a document.write() from an onclick on a button. the document.write() is overwriting everyting on the page. i just want to add it to the stuff already on the page. when i call the function by itself (not from the onclick) it appends instead of rewriting. anyone familiar with this? thx
-
Oct 28, 2003, 20:10 #2
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can't use document.write() after the current document is fully loaded (and therefore, closed). Using document.write() after pageload creates a new document and writes to it, which is why your page goes blank -- the new document replaces the current one.
You will need to use the DOM to manipulate and/or create text and elements instead.
What sort of stuff are you adding?
-
Oct 29, 2003, 03:38 #3
- Join Date
- Oct 2003
- Location
- England, Wiltshire
- Posts
- 74
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Nails 11.
Here is an example of how I insert text on the fly, should help you I think..
Hey anyone know how to paste HTML code into a reply.. oh well.
<html>
<table>
<td>
Test of inserting Text
<td>
<td>
<input type = button name=cmdInsert onclick="insertText()">
</td>
<td>
<div name="insertedText" id=insertedText></div>
</td>
<script>
function insertText()
{
insertedText.innerHTML = "Inserted Text"
}
</script>
-
Oct 29, 2003, 09:10 #4
- Join Date
- Dec 2002
- Location
- Alabama, USA
- Posts
- 2,560
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Mark_Elford
Cross-Browser.com, Home of the X Library
-
Oct 29, 2003, 09:18 #5
- Join Date
- Oct 2003
- Location
- England, Wiltshire
- Posts
- 74
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ahhhh, I see so if I do This it should paste in correctly instead of actually giving the output of my code. : -
HTML Code:<html> <table> <td> Test of inserting Text <td> <td> <input type = button name=cmdInsert onclick="insertText()"> </td> <td> <div name="insertedText" id=insertedText></div> </td> <script> function insertText() { insertedText.innerHTML = "Inserted Text" } </script>
-
Oct 29, 2003, 11:46 #6
- Join Date
- May 2003
- Posts
- 1,843
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:insertedText.innerHTML = "Inserted Text"
Code:document.getElementById('insertedText').innerHTML = "Inserted Text"
Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>untitled</title> <style type="text/css"> p {font: 600 16px verdana; color: #6699cc;} </style> <script type="text/javascript" language="javascript"> function insert_it(what, where) { where = document.getElementById(where); where.innerHTML = what; } var imgtag = '<img src="http://www.sitepointforums.com/images/icons/icon6.gif">stuff'; </script> </head> <body> <p></p> <p> i just want to add it to the <span id="poke"> <img src="http://www.sitepointforums.com/images/icons/icon5.gif"></span> already on the page. </p> <input type="button" value="stuff" onclick="insert_it(this.value,'poke')"> <input type="button" value="junk" onclick="insert_it(this.value,'poke')"> <input type="button" value="incredible mishmash" onclick="insert_it('<i>' + this.value + '</i>','poke')"> <input type="button" value="HTML" onclick="insert_it('<small>' + this.value + '</small>','poke')"> <input type="button" value="kewl" onclick="insert_it(imgtag,'poke')"> </body> </html>
::: certified wild guess :::
Bookmarks