HTML Goodies: Script Tip: Week 19
WEBINAR: On-demand webcast
How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >
Tips! My Man...
Check Out The Script
And See It In Action
The script will ask the viewer what background and text colors they would like, then the page will display with those colors. Finally, the viewer will be told, in the status bar, "Here's your color background and colortext."
The quickest way to implement the user's background and text color requests would be to write them to the <BODY> flag.
This script's main purpose is to write the HTML document's <BODY> flag to the page so we have to make sure that the entire script sits right where the <BODY> sits on the HTML page. And of course, we need to make sure we don't write a <BODY> flag into the HTML document ourselves. We need to let the script do that for us.
Here's the code that writes the <BODY> flag.
document.write("<BODY BGCOLOR=" +color+ " TEXT=" +txtcolor+ ">")
You already know what the double quotes and plus signs mean. The double quotes surround text to be written to the page, while the plus signs surround something that will be returned from the script somehow. In this script we know that data will come from the user because we're using two prompt commands to ask for colors.
Let's set up an example. If the user enters "blue" as the page background and "yellow" as the text color, this will be written to the page as the <BODY> flag:
And since we have placed the script so that that line is written where the <BODY> flag would normally go, it acts as the <BODY> flag for the page. Thus the command runs and we see the color combinations on the page. Very clever.
Next Week: How Did That Text Get Into The Status Bar?
HTML Goodies 30-Step Primer Series
and take the knowledge home with you in
on your Web pages here!