473,513 Members | 10,313 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 #1
25 3425
jullag wrote on 19 sep 2005 in comp.lang.javascript:
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


document.write() can be used anywhere in a html document, but it should
only be used before the document is fully loaded and an implicit
document.close() is issued.

Any next document.write() will implicidly do a document.open(), thereby
destroying the whole page inclusive of any onpage javascript.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Sep 19 '05 #2
jullag wrote:
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


document.getElementById("MyDiv").innerHTML="whatev er"
--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Sep 19 '05 #3
Dr Clue wrote:
jullag wrote:
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



document.getElementById("MyDiv").innerHTML="whatev er"


I'm also having a document.write() problem.. document.write is
generated dynamically, and everything else in the page disappears when
document.write() executes.. thank you...

Frances
Sep 19 '05 #4
Lee
Frances said:

Dr Clue wrote:
jullag wrote:
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



document.getElementById("MyDiv").innerHTML="whatev er"


I'm also having a document.write() problem.. document.write is
generated dynamically, and everything else in the page disappears when
document.write() executes.. thank you...


That's exactly what document.write() is supposed to do.
The first call to document.write() after the page has been displayed
generates a call to document.open(), to re-open it for writing.
document.open(), in turn, always calls document.clear();

Sep 19 '05 #5

jullag wrote:
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


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.getElementById("mydiv");
var text = document.createTextNode("my text");
div.appendChild(text);

OR

document.getElementById("mydiv").innerHTML = "my text";

Hope this helps. :)

Sep 19 '05 #6
JRS: In article <43*********************@news.sunsite.dk>, dated Mon,
19 Sep 2005 13:48:51, seen in news:comp.lang.javascript, Frances
<fd***@yahoo.com> posted :
Dr Clue wrote:
jullag wrote:
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?
document.getElementById("MyDiv").innerHTML="whatev er"


I'm also having a document.write() problem.. document.write is
generated dynamically, and everything else in the page disappears when
document.write() executes.. thank you...


Both respondents, and the OP, should read the newsgroup FAQ.

To be clueful, recommendation of getElementByID should be accompanied by
noting that it does not work on all browsers (see FAQ) and that it can
be emulated well enough for some of the others.

if (document.all && !document.getElementById) {
document.getElementById = function(id) { return document.all[id] } }

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 19 '05 #7
Dr John Stockton said the following on 9/19/2005 4:20 PM:
JRS: In article <43*********************@news.sunsite.dk>, dated Mon,
19 Sep 2005 13:48:51, seen in news:comp.lang.javascript, Frances
<fd***@yahoo.com> posted :
Dr Clue wrote:
jullag wrote:
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?
document.getElementById("MyDiv").innerHTML="wha tever"


I'm also having a document.write() problem.. document.write is
generated dynamically, and everything else in the page disappears when
document.write() executes.. thank you...

Both respondents, and the OP, should read the newsgroup FAQ.

To be clueful, recommendation of getElementByID should be accompanied by
noting that it does not work on all browsers (see FAQ) and that it can
be emulated well enough for some of the others.

if (document.all && !document.getElementById) {
document.getElementById = function(id) { return document.all[id] } }


And that it is only needed for a browser that is almost 10 years old?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 19 '05 #8

jullag wrote:
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


It is interesting that document.write is taboo in xhtml 1.1 served
correctly as application/xhtml+xml. Most of the recent browsers can
handle this mime type, but not the badly outmoded IE6(you can use a php
include at the very top of the page to automatically rewrite the code
as html 4.01 strict if you run into an outmoded browser). When you
write in xhtml 1.1 and serve as the correct mentioned mime type, modern
browsers including Opera and the Mozilla family(Mozilla, Firefox,
Netscape) become extremely strict and parse the code as xml. One reason
a document.write can not be allowed, is there is no telling what it
might write including tags that are not closed or xml forbidden
characters. Thus document.write can not be allowed. If you use
document.write, even in an external script, the page will not display
and you may get a xml parse error message from the browser. I often use
server-side php script to get around this problem. For example, my
60000 year perpetual calendar needs hundreds of divisions to write a
calendar for a full year. This was done with javascript using a
document.write at the bottom of a nest of 4 "for" loops to write all of
the divisions. This all had to go on conversion to xhtml 1.1 served
with the proper mime type. One enters the desired year, which is sent
to the server. Then the server uses php to write the code for the
calendar for the selected year, which produces hundreds of divisions.
This code is then downloaded to the browser, and the xml parser is
pleased because it can check all of the computed divisions for closing
tags, xml forbidden characters, and such. Many are kicking and
screaming about using true xhtml, but it can be done now in most cases
with automatic conversion to html 4.01 strict for outmoded browsers. If
one only considered PCs, there might be little justification for xhtml
and xml purity. However there are now a large number of computing
devices out there in addition to PCs. To allow the many devices to
exchange information, they all need to conform to xml or some other
standard they they all can understand. For now, xml seems to be the
best common language for most devices that we have.

Sep 20 '05 #9
JRS: In article <49********************@comcast.com>, dated Mon, 19 Sep
2005 18:58:42, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
Dr John Stockton said the following on 9/19/2005 4:20 PM:
To be clueful, recommendation of getElementByID should be accompanied by
noting that it does not work on all browsers (see FAQ) and that it can
be emulated well enough for some of the others.

if (document.all && !document.getElementById) {
document.getElementById = function(id) { return document.all[id] } }


And that it is only needed for a browser that is almost 10 years old?


You exaggerate : the system age is less than three-quarters of that.

Not everyone uses the latest systems (vulnerable to the latest malware).
Indeed, you yourself are using, AIUI, an out-of-date newsreader.

<QUOTE>
Can

User-Agent: Mozilla Thunderbird 0.7.2 (Windows/20040707)
X-Accept-Language: en-us, en

be set to properly unambiguous date-stamps, rather than such as

9/1/2005 6:13 PM meaning Sep 1st

and, if so, how?


I don't think it's alterable, but there have been several upgrades
since then. Version 1.0.2 gives the proper dd mmm yyyy hh:mm:ss format.

</QUOTE>

Of course, even that format is not as proper as it would be if it
followed ISO 8601.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Sep 20 '05 #10
web.dev wrote:
jullag wrote:
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

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.getElementById("mydiv");
var text = document.createTextNode("my text");
div.appendChild(text);

OR

document.getElementById("mydiv").innerHTML = "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.selectedIndex].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.getElementById("divPricing");
var divCopy = document.createTextNode(copy);
// div.appendChild(divCopy); // ******* prints 'NaN'

document.getElementById("divPricing").innerHTML = 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.createElement("iframe");
iframe.src = "http://www.google.co.uk";
document.getElementById("body").appendChild( iframe );
}

I have adapted yr function as follows:

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

var iframe = document.createElement("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.getElementById("divPricing").appendChild( iframe );
}

this line

changed to
document.getElementById("divPricing").appendChild( iframe );

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

thank you very much..

Frances


Sep 21 '05 #13
I fyou are getting ("document.getElementById("") 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.getElementById("divPricing").appendChild( 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.selectedIndex].value; and not just list.value. they
are the same.

Sep 21 '05 #14
km0ti0n wrote:
I fyou are getting ("document.getElementById("") 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.getElementById("divPricing").appendChild( 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.selectedIndex].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">Doc 1</option>
<option value="doc2">Doc 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.getElementById("") 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.getElementById("divPricing").appendChild( 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.selectedIndex].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">Product One</option>
<option value="val2">Product Two</option>
<option value="val3">Product Three</option>
<option value="val4">Product 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.getElementById("divPricing");
var divCopy = document.createTextNode(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.getElementById("") 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.getElementById("divPricing").appendChild( 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.selectedIndex].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">Product One</option>
<option value="val2">Product Two</option>
<option value="val3">Product Three</option>
<option value="val4">Product 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.getElementById("divPricing");
var divCopy = document.createTextNode(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.createElement("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.getElementById("divPricing").appendChild( 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.getElementById("") 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.getElementById("divPricing").appendChild( 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.selectedIndex].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">Product One</option>
<option value="val2">Product Two</option>
<option value="val3">Product Three</option>
<option value="val4">Product 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.getElementById("divPricing");
var divCopy = document.createTextNode(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.createElement("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.getElementById("") 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.getElementById("divPricing").appendChild( 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.selectedIndex].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">Product One</option>
<option value="val2">Product Two</option>
<option value="val3">Product Three</option>
<option value="val4">Product 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.getElementById("divPricing");
var divCopy = document.createTextNode(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.createElement("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.getElementById("") 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.getElementById("divPricing").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.selectedIndex].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">Product One</option>
<option value="val2">Product Two</option>
<option value="val3">Product Three</option>
<option value="val4">Product 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.getElementById("divPricing");
var divCopy = document.createTextNode(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.createElement("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.createElement("iframe");
ifr.src = 'iframes/' + selItem + '.html';
ifr.scrolling = 'no';
ifr.style.borderWidth='0'; // this only stuff that's not working..
document.getElementById("divPricing").appendChild( 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

Frances wrote:
web.dev wrote:
Frances wrote:
Frances wrote:

Frances wrote:
>km0ti0n wrote:
>
>
>>I fyou are getting ("document.getElementById("") 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.getElementById("divPricing").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.selectedIndex].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">Product One</option>
><option value="val2">Product Two</option>
><option value="val3">Product Three</option>
><option value="val4">Product 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.getElementById("divPricing");
>var divCopy = document.createTextNode(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.createElement("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.createElement("iframe");
ifr.src = 'iframes/' + selItem + '.html';
ifr.scrolling = 'no';
ifr.style.borderWidth='0'; // this only stuff that's not working..


It is working. But it's probably not the border you were thinking of.
That border is for placing a border around the entire iframe. And if
that's the case, then you still have what you asked for, a zero border.
But if you wanted something visible, you might also want to set the
borderStyle and the borderColor.
document.getElementById("divPricing").appendChild( 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


Hiding the other frames with css is not a good solution. Consider
this, what if the user continuously selects a different product? Then
the page will continue to append a new child.

What you'll have to do is use the replaceChild method.

document.getElementById("id").appendChild(newChild , oldChild);

Sep 21 '05 #21
km0ti0n wrote:
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


The value property of an HTMLSelectElement is specified in the W3C HTML
DOM standard, and is a formalisation of pre-existing behaviour from some
browser implementations. It was not universal at the time of its
standardisation and so its use in place of looking up the value of a
selected option with the selectedIndex property will needlessly
sacrifice browser compatibility. This would not be wise in a script such
as a form validation script that does not itself have a dependency on
other more recent DOM features.

Richard.
Sep 22 '05 #22
Frances wrote:
<snip>
var copy =+ '</iframe>'; // ******** prints 'NaN'

<snip>

The compound assignment and concatenation operator is +=, you have
written =+, which is assignment and unary plus. Unary plus type-converts
its string operand - "</iframe>" - into the number NaN, and then the
assignment replaces the value of - copy - with that NaN value.

Richard.
Sep 22 '05 #23
Dr John Stockton said the following on 9/20/2005 4:04 PM:
JRS: In article <49********************@comcast.com>, dated Mon, 19 Sep
2005 18:58:42, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
Dr John Stockton said the following on 9/19/2005 4:20 PM:
To be clueful, recommendation of getElementByID should be accompanied by
noting that it does not work on all browsers (see FAQ) and that it can
be emulated well enough for some of the others.

if (document.all && !document.getElementById) {
document.getElementById = function(id) { return document.all[id] } }


And that it is only needed for a browser that is almost 10 years old?

You exaggerate : the system age is less than three-quarters of that.


I said nothing about system age, I said the browser is almost 10 years old.

And considering that IE4.0 was released in October of 1997, that makes
the browser a tad under 8 years old. And in the age of the Web, that is
ancient.
Not everyone uses the latest systems (vulnerable to the latest malware).
Not all latest systems are vulnerable to that malware. It only takes a
little common sense and understanding of your computer to keep it free
of malware.
Indeed, you yourself are using, AIUI, an out-of-date newsreader.
Oh well.
<QUOTE>
Can

User-Agent: Mozilla Thunderbird 0.7.2 (Windows/20040707)
X-Accept-Language: en-us, en

be set to properly unambiguous date-stamps, rather than such as

9/1/2005 6:13 PM meaning Sep 1st

and, if so, how?
I don't think it's alterable, but there have been several upgrades
since then. Version 1.0.2 gives the proper dd mmm yyyy hh:mm:ss format.


If it did, I would change it back to the way I have this one set as it
is in the format I prefer. The only people that seem to have a problem
with my date format are people who have nothing better to whine about
than a date format. And anybody who confuses the date of 9/1/2005 with
1/9/2005 in Usenet context doesn't need a Newsreader, they need a head
shrink.
</QUOTE>

Of course, even that format is not as proper as it would be if it
followed ISO 8601.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 22 '05 #24
Richard Cornford wrote:
km0ti0n wrote:
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

The value property of an HTMLSelectElement is specified in the W3C HTML
DOM standard, and is a formalisation of pre-existing behaviour from some
browser implementations. It was not universal at the time of its
standardisation and so its use in place of looking up the value of a
selected option with the selectedIndex property will needlessly
sacrifice browser compatibility. This would not be wise in a script such
as a form validation script that does not itself have a dependency on
other more recent DOM features.

Richard.


yes, I tried this, it works.. thank you.. I like it, simpler than other
way... (also thanks for pointing out I had wrong var decl (=+ instead
of +=..)
Sep 22 '05 #25
web.dev wrote:
Frances wrote:

document.getElementById("divPricing").appendChild( 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

Hiding the other frames with css is not a good solution. Consider
this, what if the user continuously selects a different product? Then
the page will continue to append a new child.

What you'll have to do is use the replaceChild method.

document.getElementById("id").appendChild(newChild , oldChild);


thank you very much for yr help.... so in order for this to work I have
to put a blank iframe there initially so I can replace it afterwards..
this is how I figured, but unfortunately having some problems...

var selItem;
var ifrCurr;
var div = document.getElementById("divPricing");
// this var not being read inside functions..
// (even if I take out 'var' from declaration..)

function currIF() { // to put a blank iframe..
ifrCurr = document.createElement("iframe");
ifrCurr.src = 'iframes/blank.html';
//div.appendChild(ifrCurr); // ****** var not being read...

document.getElementById("divPricing").appendChild( ifrCurr);
// errror on this line
// is null or not an obj... (??)
// no problem w/this line in below function..
}
window.onload=currIF();

function pricing() {
selItem = document.getElementById("product").value;
var ifr = document.createElement("iframe");
ifr.src = 'iframes/' + selItem + '.html';
ifr.scrolling = 'no';
ifr.style.borderWidth='0';
ifr.setAttribute(selItem, name);
document.getElementById("divPricing").appendChild( ifr);
// div.appendChild(ifr); // ******* var not being read...

// document.getElementById("divPricing").replaceChild (ifr,ifrCurr);
// can't use this line yet b/c problems w/function above....
}

thank you very much........ Frances
Sep 22 '05 #26

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

Similar topics

1
2856
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();'>");...
3
9817
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...
2
2366
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...
10
13652
by: Rithish | last post by:
I want to emulate paging in an HTML document. something like, ------------------------- | | | <DIV> | | | | <TABLE></TABLE>...
4
2957
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...
4
1424
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
3303
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...
5
2957
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...
5
3993
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
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
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...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7094
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...
0
7519
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...
0
5677
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,...
0
4743
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...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.