473,800 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

random background colors

4 New Member
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 1902
jsakalos
12 New Member
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
markfrmtls
4 New Member
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
jsakalos
12 New Member
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
markfrmtls
4 New Member
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 Recognized Expert Moderator MVP
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
8685
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 say the header won't. The below style will display the borders in print preview, but won't display the background color. Does anyone know if it's possible to force background CSS or HTML colors to print without having the user change the default...
10
2508
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 spots on the webpage. with a delay timer on them, so they keep changing as the page is open. Not random each time the page is loaded. If anyone can help it would be greatly appreaciated, I have tried many of
25
12945
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 on what browsers have difficulty with the non-shortcut methods of setting background properties?
3
4766
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
3942
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 existence.... So, is there a way in CSS to say "Yeah, print these background colors", without the user having to turn on an option that will then apply to all pages printed? Thanks,
4
4099
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 so, how? See my HTML below (or go to my test page at http://fmbbowen.com:39353/misc/Misc.html). I also tried treating ..color as a number and subtracting the current color from 0xFFFFFF but that did not work either. The numerous examples I...
10
7733
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, there is nothing !!! How to print such lines colors ? the main purpose of this table is to be
12
3100
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 random colors, I feel that there should also be some condition to ensure that they aren't too similar in appearance, given that is likely to range from 2-20 say. Any help much appreciated,
2
1815
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
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10279
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10255
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9092
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.