document.write colour

G

Geoff

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

Randy Webb

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

Robert Degen

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
 
G

Geoff

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,
 
M

mick white

Geoff said:
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
 
E

Evertjan.

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
}
 
G

Geoff

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

Evertjan.

Geoff wrote on 26 jan 2006 in comp.lang.javascript:
[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.
 
L

Lee

Geoff said:
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.

document.write("<body bgcolor='green'>"
+"This is the correct number"
+"</body>");

But you'll find that document.write() isn't really a very good
way to make dynamic changes to you pages.'
 
V

VK

Geoff said:
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();
 
G

Geoff

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

Geoff.
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Thu, 26 Jan 2006 12:44:45 remote, seen in
news:comp.lang.javascript said:
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".
 

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

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,192
Latest member
KalaReid2

Latest Threads

Top