473,770 Members | 2,144 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.write( ) in the middle of a document?

Hi,

does anyone know of any javascript method that does the same job as
document.write( ), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
thanks a lot
JL

Sep 19 '05
25 3506
web.dev wrote:
jullag wrote:
Hi,

does anyone know of any javascript method that does the same job as
document.writ e(), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
thanks a lot
JL

Hi JL,

Off the top of my head, I can think of 2 ways.

Suppose you had an element:

<div id = "mydiv"></div>

and you wanted to insert text in between the div tag. You can do the
following:

var div = document.getEle mentById("mydiv ");
var text = document.create TextNode("my text");
div.appendChild (text);

OR

document.getEle mentById("mydiv ").innerHTM L = "my text";

Hope this helps. :)


ok, I'm following advice here.. but it's not working right...

function pricing() {
var list = document.forms[0].product;
var selItem = list.options[list.selectedIn dex].value;
// alert('iframes/' + selItem + '.html');

// var copy = 'yada yada'; // ***** prints fine..

var copy = '<iframe src="iframes/' + selItem + '.html" scrolling=no
width=300 height=200 frameborder=0>' ;
var copy =+ '</iframe>'; // ******** prints 'NaN'

var div = document.getEle mentById("divPr icing");
var divCopy = document.create TextNode(copy);
// div.appendChild (divCopy); // ******* prints 'NaN'

document.getEle mentById("divPr icing").innerHT ML = divCopy;
// **** prints '[object]'
// whether plain text or "<iframe>.. ." in var 'copy'
}

would appreciate some leads.. thank you very much...

Frances

Sep 21 '05 #11
Hi

First thing i notice is the way you are referencing the value of the
select please read this :

http://km0ti0n.blunted.co.uk/viewfaq...29154586250000

Ok so you want to create HTML dynamically. There's a workign example
here:

http://km0ti0n.blunted.co.uk/Using%2...ate%20html.xap

As for adding an iframe I had to think for a minuite to ensure it was
possible to append an iframe using DOM methods. I made you this
example.

http://km0ti0n.blunted.co.uk/viewng....29149606406250

Hope it helps

Sep 21 '05 #12
km0ti0n wrote:
Hi

First thing i notice is the way you are referencing the value of the
select please read this :

http://km0ti0n.blunted.co.uk/viewfaq...29154586250000

Ok so you want to create HTML dynamically. There's a workign example
here:

http://km0ti0n.blunted.co.uk/Using%2...ate%20html.xap

As for adding an iframe I had to think for a minuite to ensure it was
possible to append an iframe using DOM methods. I made you this
example.

http://km0ti0n.blunted.co.uk/viewng....29149606406250

Hope it helps

thank you very much for yr help...

I have a few questions about yr example..

function test() {
var iframe = document.create Element("iframe ");
iframe.src = "http://www.google.co.u k";
document.getEle mentById("body" ).appendChild( iframe );
}

I have adapted yr function as follows:

function pricing() {
list = document.forms[0].product;
selItem = list.options[list.selectedIn dex].value;

var iframe = document.create Element("iframe ");
// iframe.src = "iframes/cc.html"; // works fine..
// file I want to see shows up fine...

iframe.src = "iframes/' + selItem + '.html"; // get a 404...
// ?? alert below prints what I expect it to..
// shows correct path to file..
alert('iframes/' + selItem + '.html');

document.getEle mentById("divPr icing").appendC hild( iframe );
}

this line

changed to
document.getEle mentById("divPr icing").appendC hild( iframe );

b/c this iframe goes inside a div (a div nested inside another div..)
and either way when did
document.getEle mentById("body" ).appendChild( iframe );
got an error..
("document.getE lementById("") is null or not an object..")

thank you very much..

Frances


Sep 21 '05 #13
I fyou are getting ("document.getE lementById("") is null or not an
object..") errors make sure you are referenceing the element correctly.
By checking the ID of the element is correct and make sure the the
elements id isn't duplicated.

I see you have this

document.getEle mentById("divPr icing").appendC hild( iframe );

You should have the corrisponding HTML :

<div id="divPricing" > .... </div>

Normally it's a typo....

Also you are *STILL* using selItem =
list.options[list.selectedIn dex].value; and not just list.value. they
are the same.

Sep 21 '05 #14
km0ti0n wrote:
I fyou are getting ("document.getE lementById("") is null or not an
object..") errors make sure you are referenceing the element correctly.
By checking the ID of the element is correct and make sure the the
elements id isn't duplicated.

I see you have this

document.getEle mentById("divPr icing").appendC hild( iframe );

You should have the corrisponding HTML :

<div id="divPricing" > .... </div>

Normally it's a typo....

Also you are *STILL* using selItem =
list.options[list.selectedIn dex].value; and not just list.value. they
are the same.


you're right -- I just changed that.. however on larger problem:

yes, corresponding HTML IS there for div..

<div id="divPricing" >
</div>

and positioned w/css where I want it..

funny thing I noticed is that behavior is exactly the same whether or
not I put quotes in <option> tags..

<option value="doc1">Do c 1</option>
<option value="doc2">Do c 2</option>

<option value=doc1>Doc 1</option>
<option value=doc2>Doc 2</option>

exact same behavior here in both cases...
???

again many thanks for yr help..

Sep 21 '05 #15
km0ti0n wrote:
I fyou are getting ("document.getE lementById("") is null or not an
object..") errors make sure you are referenceing the element correctly.
By checking the ID of the element is correct and make sure the the
elements id isn't duplicated.

I see you have this

document.getEle mentById("divPr icing").appendC hild( iframe );

You should have the corrisponding HTML :

<div id="divPricing" > .... </div>

Normally it's a typo....

Also you are *STILL* using selItem =
list.options[list.selectedIn dex].value; and not just list.value. they
are the same.


ok, am trying a different approach, iframes print w/a border that I
can't get rid of.. not sure yet whether will go w/iframes or not, but at
any rate am having problems w/this approach also:

in <body>:
<option value="val1">Pr oduct One</option>
<option value="val2">Pr oduct Two</option>
<option value="val3">Pr oduct Three</option>
<option value="val4">Pr oduct Four</option>

in <head>:
function pricing() {
var val1 = "Product One";
var val2 = "Product Two";
var val3 = "Product Three";
var val4 = "Product Four";

var list = document.forms[0].product;
var selItem = list.value;
var copy = "" + selItem + "";
var div = document.getEle mentById("divPr icing");
var divCopy = document.create TextNode(copy);

div.appendChild (divCopy); // prints, for example,
// (no quotes) 'val4' instead of 'Product Four'...

// div.innerHTML = divCopy; // this prints '[object]' (no quotes)
}
again many thanks for your help...... Frances
Sep 21 '05 #16
Frances wrote:
km0ti0n wrote:
I fyou are getting ("document.getE lementById("") is null or not an
object..") errors make sure you are referenceing the element correctly.
By checking the ID of the element is correct and make sure the the
elements id isn't duplicated.

I see you have this

document.getEle mentById("divPr icing").appendC hild( iframe );

You should have the corrisponding HTML :

<div id="divPricing" > .... </div>

Normally it's a typo....

Also you are *STILL* using selItem =
list.options[list.selectedIn dex].value; and not just list.value. they
are the same.

ok, am trying a different approach, iframes print w/a border that I
can't get rid of.. not sure yet whether will go w/iframes or not, but at
any rate am having problems w/this approach also:

in <body>:
<option value="val1">Pr oduct One</option>
<option value="val2">Pr oduct Two</option>
<option value="val3">Pr oduct Three</option>
<option value="val4">Pr oduct Four</option>

in <head>:
function pricing() {
var val1 = "Product One";
var val2 = "Product Two";
var val3 = "Product Three";
var val4 = "Product Four";

var list = document.forms[0].product;
var selItem = list.value;
var copy = "" + selItem + "";
var div = document.getEle mentById("divPr icing");
var divCopy = document.create TextNode(copy);

div.appendChild (divCopy); // prints, for example,
// (no quotes) 'val4' instead of 'Product Four'...

// div.innerHTML = divCopy; // this prints '[object]' (no quotes)
}
again many thanks for your help...... Frances

ok, I think I need to go back to iframes..

the problem is a very odd one.. pls see below:

function pricing() {
var list = document.forms[0].product;
var selItem = list.value;
var ifr = document.create Element("iframe ");
//ifr.src = "iframes/' + selItem + '.html"; // *** get a 404..

look @ 2 following lines.. this is very weird..
ifr.src = "iframes/' + 'aa' + '.html"; // **** get a 404..
// ifr.src = "iframes/aa.html"; // *****loads fine..

document.getEle mentById("divPr icing").appendC hild( ifr );
}

I can't just put divs there or do show/hide divs b/c this is for a div
nested in another div which itself is hidden or visible depending on
user input.. would appreciate any help here.. thank you very much...

Sep 21 '05 #17
Frances wrote:
Frances wrote:
km0ti0n wrote:
I fyou are getting ("document.getE lementById("") is null or not an
object..") errors make sure you are referenceing the element correctly.
By checking the ID of the element is correct and make sure the the
elements id isn't duplicated.

I see you have this

document.getEle mentById("divPr icing").appendC hild( iframe );

You should have the corrisponding HTML :

<div id="divPricing" > .... </div>

Normally it's a typo....

Also you are *STILL* using selItem =
list.options[list.selectedIn dex].value; and not just list.value. they
are the same.


ok, am trying a different approach, iframes print w/a border that I
can't get rid of.. not sure yet whether will go w/iframes or not, but
at any rate am having problems w/this approach also:

in <body>:
<option value="val1">Pr oduct One</option>
<option value="val2">Pr oduct Two</option>
<option value="val3">Pr oduct Three</option>
<option value="val4">Pr oduct Four</option>

in <head>:
function pricing() {
var val1 = "Product One";
var val2 = "Product Two";
var val3 = "Product Three";
var val4 = "Product Four";

var list = document.forms[0].product;
var selItem = list.value;
var copy = "" + selItem + "";
var div = document.getEle mentById("divPr icing");
var divCopy = document.create TextNode(copy);

div.appendChild (divCopy); // prints, for example,
// (no quotes) 'val4' instead of 'Product Four'...

// div.innerHTML = divCopy; // this prints '[object]' (no quotes)
}
again many thanks for your help...... Frances


ok, I think I need to go back to iframes..

the problem is a very odd one.. pls see below:

function pricing() {
var list = document.forms[0].product;
var selItem = list.value;
var ifr = document.create Element("iframe ");
//ifr.src = "iframes/' + selItem + '.html"; // *** get a 404..

look @ 2 following lines.. this is very weird..
ifr.src = "iframes/' + 'aa' + '.html"; // **** get a 404..


ok, above line is wrong (the quotes..)
however when did this still got 404..

ifr.src = '"iframes/' + 'aa' + '.html"';

only way finally got it to work:

ifr.src = 'iframes/' + selItem + '.html';

?????
(tried to escape that double-quote like you do in java, but also no go..)
Sep 21 '05 #18

Frances wrote:
Frances wrote:
Frances wrote:
km0ti0n wrote:

I fyou are getting ("document.getE lementById("") is null or not an
object..") errors make sure you are referenceing the element correctly.
By checking the ID of the element is correct and make sure the the
elements id isn't duplicated.

I see you have this

document.getEle mentById("divPr icing").appendC hild( iframe );

You should have the corrisponding HTML :

<div id="divPricing" > .... </div>

Normally it's a typo....

Also you are *STILL* using selItem =
list.options[list.selectedIn dex].value; and not just list.value. they
are the same.

ok, am trying a different approach, iframes print w/a border that I
can't get rid of.. not sure yet whether will go w/iframes or not, but
at any rate am having problems w/this approach also:

in <body>:
<option value="val1">Pr oduct One</option>
<option value="val2">Pr oduct Two</option>
<option value="val3">Pr oduct Three</option>
<option value="val4">Pr oduct Four</option>

in <head>:
function pricing() {
var val1 = "Product One";
var val2 = "Product Two";
var val3 = "Product Three";
var val4 = "Product Four";

var list = document.forms[0].product;
var selItem = list.value;
var copy = "" + selItem + "";
var div = document.getEle mentById("divPr icing");
var divCopy = document.create TextNode(copy);

div.appendChild (divCopy); // prints, for example,
// (no quotes) 'val4' instead of 'Product Four'...

// div.innerHTML = divCopy; // this prints '[object]' (no quotes)
}
again many thanks for your help...... Frances
ok, I think I need to go back to iframes..

the problem is a very odd one.. pls see below:

function pricing() {
var list = document.forms[0].product;
var selItem = list.value;
var ifr = document.create Element("iframe ");
//ifr.src = "iframes/' + selItem + '.html"; // *** get a 404..

look @ 2 following lines.. this is very weird..
ifr.src = "iframes/' + 'aa' + '.html"; // **** get a 404..


ok, above line is wrong (the quotes..)
however when did this still got 404..

ifr.src = '"iframes/' + 'aa' + '.html"';


I don't see why you even need to place in double quotes. The whole
thing is a string value. The above code statement is equivalent to the
following:

ifr.src = '"iframes/aa.html"';

When all you really could've done is:

ifr.src = 'iframes/aa.html';

only way finally got it to work:

ifr.src = 'iframes/' + selItem + '.html';
The solution you're presenting here does not really relate to the above
problem you mentioned.

?????
(tried to escape that double-quote like you do in java, but also no go..)


If you're having trouble with javascript, I would rather you post your
own thread instead of using someone else's.

Sep 21 '05 #19
web.dev wrote:
Frances wrote:
Frances wrote:
Frances wrote:
km0ti0n wrote:
>I fyou are getting ("document.getE lementById("") is null or not an
>object.. ") errors make sure you are referenceing the element correctly.
> By checking the ID of the element is correct and make sure the the
>elements id isn't duplicated.
>
>I see you have this
>
>document.g etElementById(" divPricing").ap pendChild( iframe );
>
>You should have the corrisponding HTML :
>
><div id="divPricing" > .... </div>
>
>Normally it's a typo....
>
>Also you are *STILL* using selItem =
>list.optio ns[list.selectedIn dex].value; and not just list.value. they
>are the same.

ok, am trying a different approach, iframes print w/a border that I
can't get rid of.. not sure yet whether will go w/iframes or not, but
at any rate am having problems w/this approach also:

in <body>:
<option value="val1">Pr oduct One</option>
<option value="val2">Pr oduct Two</option>
<option value="val3">Pr oduct Three</option>
<option value="val4">Pr oduct Four</option>

in <head>:
function pricing() {
var val1 = "Product One";
var val2 = "Product Two";
var val3 = "Product Three";
var val4 = "Product Four";

var list = document.forms[0].product;
var selItem = list.value;
var copy = "" + selItem + "";
var div = document.getEle mentById("divPr icing");
var divCopy = document.create TextNode(copy);

div.appendChild (divCopy); // prints, for example,
// (no quotes) 'val4' instead of 'Product Four'...

// div.innerHTML = divCopy; // this prints '[object]' (no quotes)
}
again many thanks for your help...... Frances

ok, I think I need to go back to iframes..

the problem is a very odd one.. pls see below:

function pricing() {
var list = document.forms[0].product;
var selItem = list.value;
var ifr = document.create Element("iframe ");
//ifr.src = "iframes/' + selItem + '.html"; // *** get a 404..

look @ 2 following lines.. this is very weird..
ifr.src = "iframes/' + 'aa' + '.html"; // **** get a 404..


ok, above line is wrong (the quotes..)
however when did this still got 404..

ifr.src = '"iframes/' + 'aa' + '.html"';

I don't see why you even need to place in double quotes. The whole
thing is a string value. The above code statement is equivalent to the
following:

ifr.src = '"iframes/aa.html"';


ok, what confused me is that in TAG (<iframe>) you have to put (I think)
attr under src in quotes (<iframe src="file.html" ..>) is this right? at
any rate not sure this is 100% required so left them out.. but of course
you're right, I'm not even generating iframe w/a conventional tag so I
guess that requirement doesn't apply..

finally got this to work thus:

list = document.forms[0].product;
selItem = list.value;
var ifr = document.create Element("iframe ");
ifr.src = 'iframes/' + selItem + '.html';
ifr.scrolling = 'no';
ifr.style.borde rWidth='0'; // this only stuff that's not working..
document.getEle mentById("divPr icing").appendC hild(ifr);
problem NOW is that when user goes back to sel obj and selects a diff.
product new iframe gets placed BESIDE current one, not in same place
where other one is :( (which is weird b/c iframe is inside a div
positioned absolutely w/css.. I guess have to do the visible/hidden
thingie w/css...)

again, many thanks for your help..... Frances
Sep 21 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2873
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>"); document.write("<OPTION VALUE='0.345066110642241'>Argentina Peso </OPTION>"); document.write("<OPTION VALUE='0.790200069503053'>Australia Dollar
3
9843
by: Catherine Lynn Smith | last post by:
I am creating a webpage with dhtml <DIV> layers and I want a link on one layer to modify the content on another but I seem to keep running into errors. Basically I create a layer in the middle of the screen that initially comes up with a gif image of a house: <!-- start "house" layer definition for center of screen --> <DIV id="house" style="position:absolute; left:140px; top:137px; width:510px; height:325px; z-index:2"><img...
2
2386
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of copying/pasting everytime I change it, I figure this will be better, as I only change it once. The problem is, document.write doesn't handle multiple lines very well, so I was wondering what is the best way to do this? Maybe there is even a better...
10
13680
by: Rithish | last post by:
I want to emulate paging in an HTML document. something like, ------------------------- | | | <DIV> | | | | <TABLE></TABLE> | | | | <TABLE></TABLE> | | |
4
2983
by: Charles Crume | last post by:
Hello all; I have a web page that displays a blank gif for about 2 seconds, then displays an animated gif image, then, after the animation plays, I want to display a link so the user can click on it and go to another page. I am fairly new to javascript and came up with the following code: ----------------------- <p align="center"><img src="images/nil.gif" align="middle" width="375" height="300" name="blank_image"></p>
4
1441
by: PHP2 | last post by:
how I can create frame inside in total middle of document with? I have one htnl and I need html page totaly in middle..
12
3347
by: Radek Maciaszek | last post by:
Hi It's very interesting problem. I couldn't even find any inforamtion about it on the google. I think that the best way of explain will be this simple example: <html> <body> <script language="JavaScript" type="text/javascript" src="write.js"></script>
5
2970
by: SuneR | last post by:
Hi, I am having problems figuring out how to make Firefox behave, and output the HTML I want it to output. The thing I want done is actually quite simple. I have a <labeltag, and inside it, I have a script tag, that document.write's some HTML. Like this:
5
4014
by: ankit1999 | last post by:
I have a problem, everytime i'm run this page http://click2travel.in/index.php i get the this error,,,
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.