473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

random background colors

I am not totally a novice, but only have self-trained experience. I am looking for a way to randomly change the background color and text color with my web pages. My thought is to put a counter on my home page and every even number on the counter the background color will be yellow and every odd number the colors will change to something else. If there4 is a script for this I would be truly grateful to learn how this would work. I have posted on the CSS/HTML forum with a similar question.

Thanks for any help that can be provided.
Jun 16 '07 #1
5 1882
I would prepare an array with allowed background colors and I would use Math.random * sizeOfArray on each page load to get index to that array, took and set color from it.

This way you can keep reasonable bg colors (pseudo) randomly selected.
Jun 16 '07 #2
I would prepare an array with allowed background colors and I would use Math.random * sizeOfArray on each page load to get index to that array, took and set color from it.

This way you can keep reasonable bg colors (pseudo) randomly selected.
I am very new to js what is math.ramdom
Jun 17 '07 #3
You can find detailed information about Math object (beware, case matters) here.

There is a lot of other useful information on the main site of that link.
Jun 17 '07 #4
You can find detailed information about Math object (beware, case matters) here.

There is a lot of other useful information on the main site of that link.
I found a site with the math.object and many other scripts. I may have to learn JS. I do have a question as far as where I can insert the code. If I set up a script to run like you say. Can I insert it in the Style tag under the body property as a value. In other words ti might look like this:
<style> body background: <script>bgcolor.js</script>; </style>

I know that this code is not exactly correct, but will this work is the file is called correctly.
Jun 20 '07 #5
acoder
16,027 Expert Mod 8TB
I found a site with the math.object and many other scripts. I may have to learn JS. I do have a question as far as where I can insert the code. If I set up a script to run like you say. Can I insert it in the Style tag under the body property as a value. In other words ti might look like this:
<style> body background: <script>bgcolor.js</script>; </style>

I know that this code is not exactly correct, but will this work is the file is called correctly.
No that's incorrect. See this link which describes where to put your Javascript scripts.
Jun 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Scott | last post by:
There is a setting in IE for "Print background colors and images." I've noticed that without checking this option, a web page will print CSS lines between table rows, but a background color of...
10
by: Virus | last post by:
Ok well what I am trying to do is have 1.) the background color to change randomly with 5 different colors.(change on page load) 2,) 10 different quotes randomly fadeing in and out in random...
25
by: Neal | last post by:
According to the CSS lint at http://htmlhelp.org/tools/csscheck/, "The shorthand background property is more widely supported than background-color." Can anyone point me to, or provide, information...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
16
by: J. B. Moreno | last post by:
I read the faq, and it mentions that IE 4 on windows requires setting a printing option to allow background colors to be printed. Things change, life goes on, other browsers come into...
4
by: Franklin | last post by:
WITHOUT KNOWING ANYTHING ABOUT THE CURRENT COLORS, I want to swap the foreground/background colors of a link when someone hovers over it. Is this possible with HTML, CSS, DOM, & JavaScript? If...
10
by: Bob Bedford | last post by:
I've a table in wich I've this CSS: ..oddrow{background-color:#FFFFFF} ..evenrow{background-color:#CCCCCC} The oddrows are white and the even are grey. BUT ! when I do print the table,...
12
by: Adam Hartshorne | last post by:
Hi All, I was wondering if somebody could post a few lines of code which would produce random colors, which will be used in defining different regions on a mesh. So in addition to having n...
2
by: shapper | last post by:
Hello, How can add a background color to each table cell in a table header and also add a small image on the bottom right corner of each of those cells? Thanks, Miguel
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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
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...

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.