By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

document.write colour

P: n/a
I am using the following statement in a script:

If (res == 123) document.write (" Blah Blah");
else
document.write (" XYZ");

This of course brings up a new page on my site and prints Blah Blah.
However, the colour of the page is white & I want it to match the colour of
the html page from which the original request was sent. I have tried
playing with
document.write('<body bgcolor="green">') but either I'm placing it in the
wrong place or it doesn't work.

Can anyone help please?

Geoff.
Jan 26 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Geoff said the following on 1/26/2006 7:44 AM:
I am using the following statement in a script:

If (res == 123) document.write (" Blah Blah");
else
document.write (" XYZ");

This of course brings up a new page on my site and prints Blah Blah.
New page in the same browser window I assume is what you mean.
However, the colour of the page is white & I want it to match the colour of
the html page from which the original request was sent. I have tried
playing with
document.write('<body bgcolor="green">') but either I'm placing it in the
wrong place or it doesn't work.


Show some actual code. Nobody will be able to answer you without seeing
the code as any "answer" given would have to be a guess.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 26 '06 #2

P: n/a
On Thu, 26 Jan 2006 12:44:45 +0000, Geoff wrote:
I am using the following statement in a script:

If (res == 123) document.write (" Blah Blah");
else
document.write (" XYZ");

This of course brings up a new page on my site and prints Blah Blah.
However, the colour of the page is white & I want it to match the colour of
the html page from which the original request was sent. I have tried
playing with
document.write('<body bgcolor="green">') but either I'm placing it in
Not quite clear what you're trying to do but changing your background
color may work by...

document.body.style.background = "green";
the wrong place or it doesn't work.

Can anyone help please?

Geoff.


Post your sources.

So far

Rob
Jan 26 '06 #3

P: n/a
OK, What I am doing is taking an inputted number from an HTML page and
processing it as follows (This is the relevant part):

function check_input()
{
// get user input from text field in form id of f
var entry = document.forms.f.textfield.value;
// Input number
var num2 = entry.substr(0,3);
var res = +num2;
// Test for correctness
if(res == 936) document.write ("This is the correct number ");
else
if(res == 938) document.write ("This is the correct number ");
else
if(res == 939) document.write ("This is the correct number ");
else
if(res == 941) document.write ("This is the correct number ");
else
if(res == 942) document.write ("This is the correct number ");
else
if(res == 943) document.write ("This is the correct number ");
else
document.write (" Unfortunately, This is the wrong number ");
}

If the result is equal to one of these numbers, it will fetch a new page
with "This is the correct number" and conversely, "This is the wrong
number" if it doesn't match. This all works OK, but the new page which is
displayed with this text in, is White and I want to make it a Green.

Hope this makes it clearer.

Thanks in advance,

Geoff.

Jan 26 '06 #4

P: n/a
Geoff wrote:
OK, What I am doing is taking an inputted number from an HTML page and
processing it as follows (This is the relevant part):

function check_input()
{
// get user input from text field in form id of f
var entry = document.forms.f.textfield.value;
// Input number
var num2 = entry.substr(0,3);
var res = +num2;
// Test for correctness
if(res == 936) document.write ("This is the correct number ");
else


[...]
function check_input(){
var res = +(document.forms.f.textfield.value.substr(0,3));
document.write ("This is the "+
(res==936||res==938||res=939||res==941||res==942|| res==943?
"correct":"wrong")+" number.");
}

Strange use of document.write(), though.
Mick
Jan 26 '06 #5

P: n/a
Geoff wrote on 26 jan 2006 in comp.lang.javascript:
If the result is equal to one of these numbers, it will fetch a new
page with "This is the correct number" and conversely, "This is the
wrong number" if it doesn't match. This all works OK, but the new
page which is displayed with this text in, is White and I want to make
it a Green.


Using document.write after the page has ended loading is an error in my
view.

document.write then starts with a document.open that destroys the page,
and you will get a incomplete page instead.

Better use:
<div id='result'>No result yet.</div>

function check_input() {
var res = +document.forms.f.textfield.value.substr(0,3);
if ((res >= 936) && (res <= 943) && (res != 937) && (res != 940))
txt = 'This is the correct number'
else
txt = 'Unfortunately, this is a wrong number';
document.getElementById('result').innerHTML = txt
}

or use regex [better because it does not error for non figure strings]:

<div id='result'>No result yet.</div>

function check_input() {
var res = +document.forms.f.textfield.value;
if (/^9((3[689])||(4[123]))/.test(res))
txt = 'This is the correct number'
else
txt = 'Unfortunately, this is a wrong number';
document.getElementById('result').innerHTML = txt
}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 26 '06 #6

P: n/a
Thanks guys, but the point is being missed! My original question is
repeated below. It is how to change the colour, that I am asking. The
actual script is working OK as far as I am concerned at the moment albeit a
bit cumbersome I agree

What I want to do, is that when document.write brings up a new page, I want
to change the colour of that page from White to something else.

I was asked to send the script, which is what I did and it seemed to go off
at a tangent after that!

Thanks In Advance

Geoff.

"Geoff" <so*****@somewhere.sometime> wrote in message
news:dr**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
I am using the following statement in a script:

If (res == 123) document.write (" Blah Blah");
else
document.write (" XYZ");

This of course brings up a new page on my site and prints Blah Blah.
However, the colour of the page is white & I want it to match the colour of the html page from which the original request was sent. I have tried
playing with
document.write('<body bgcolor="green">') but either I'm placing it in the
wrong place or it doesn't work.

Can anyone help please?

Geoff.

Jan 26 '06 #7

P: n/a
Geoff wrote on 26 jan 2006 in comp.lang.javascript:
"Geoff" <so*****@somewhere.sometime> wrote in message
news:dr**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
I am using the following statement in a script:

If (res == 123) document.write (" Blah Blah");
else
document.write (" XYZ");

This of course brings up a new page on my site and prints Blah Blah.
However, the colour of the page is white & I want it to match the
colour of
the html page from which the original request was sent. I have
tried playing with
document.write('<body bgcolor="green">') but either I'm placing it in
the wrong place or it doesn't work.

Can anyone help please?


[please do not toppost on usenet]
Thanks guys, but the point is being missed! My original question is
repeated below. It is how to change the colour, that I am asking.
The actual script is working OK as far as I am concerned at the moment
albeit a bit cumbersome I agree

What I want to do, is that when document.write brings up a new page, I
want to change the colour of that page from White to something else.

I was asked to send the script, which is what I did and it seemed to
go off at a tangent after that!


That's because usenet is not a payed helpdesk and I [we?] think you are
on the wrong foot.

If you want to use document.write after pageload, you will have [I think]
to write a whole new page using document.write, which is cumbersome or be
content with a incomplete one wich I consider inadaequate.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 26 '06 #8

P: n/a
VK

Geoff wrote:
Thanks guys, but the point is being missed! My original question is
repeated below. It is how to change the colour, that I am asking. The
actual script is working OK as far as I am concerned at the moment albeit a
bit cumbersome I agree

What I want to do, is that when document.write brings up a new page, I want
to change the colour of that page from White to something else.


The color of the page is not "white" or any other in this matter,
because there is not any page as such.

If you are using document.write() method after the "load" event fired,
the real sequence is:

document.clear(); // clear page content including any scripts
document.open("text/html") // open input stream
document.write(myContent) // send your content to the open input stream
document.close() // close the input stream

Despite you "see" only your own document.write(), but clear() and
open() are applied too.
And some browsers (like FF) also require explicit close(), but some
browsers (like IE) do it for you either.

So:
document.write("Right answer");
produces a "page" like "<HTML>Right answer</HTML>" which is not a
valid page and actually God knows what it is. It has white background
because in some browsers it is the *default* one - if no background
indicated by author.

So if you want to use it as it is - it will not wark anyhow reliably.
But I leave the oppotunity to discover it on yourselve.

Just do not let you go all upset: here (it doesn't work on a long run,
but answer your immediate need):

document.clear();
document.open("text/html");
document.write("<html><head><title>-</title></head>");
// type in below any color you like:
document.write("<body bgcolor=\"yellow\">");
// type in below your content:
document.write(myContent);
document.write("</body></html>");
document.close();

Jan 26 '06 #9

P: n/a
Thanks VK! Brilliant!
This was the answer I was looking for and with slight modification, it
worked great.!

Geoff.
Jan 27 '06 #10

P: n/a
JRS: In article <dr**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com>,
dated Thu, 26 Jan 2006 12:44:45 remote, seen in
news:comp.lang.javascript, Geoff <so*****@somewhere.sometime> posted :
This of course brings up a new page on my site and prints Blah Blah.
However, the colour of the page is white & I want it to match the colour of
the html page from which the original request was sent. I have tried
playing with
document.write('<body bgcolor="green">') but either I'm placing it in the
wrong place or it doesn't work.


document.write('<body bgcolor="green"> xxx </body>')

executed in <URL:http://www.merlyn.demon.co.uk/js-quick.htm> gives me a
green body; there has to be something after green"> apparently.

So you seem to be partly right.

I use

function NewPage(Title, Body) { // Same window. Passes TIDY check.
document.writeln('<!DOCTYPE HTML PUBLIC' +
' "-//W3C//DTD HTML 4.01 Transitional//EN"\n' +
' "http://www.w3.org/TR/html4/strict.dtd">\n' +
'<HTML lang="en">\n<HEAD>\n' +
'<META HTTP-EQUIV="Content-Type"' +
' CONTENT="text/html; charset=ISO-8859-1">\n' +
'<TITLE>' + Site + ' -\n ' +
Title + '\n - ' + Owner + '<\/TITLE>\n<\/HEAD>\n<BODY>\n\n' +
Body + "\n\n<hr>\n<\/BODY>\n</\HTML>\n") }
to generate a new page holding Body and passing at least one W3
tester.
H'mmm ... maybe I should remove " Transitional".

--
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.
Jan 27 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.