User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 373,566 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,860 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Mar 16th, 2005
Views: 6,031
Shows how to connect a button onclick event to a javascript function to change the background color of the document. Just cut and paste the code into Notepad or other editor, save as BGchanger.htm and run it on your browser.
javascript Syntax | 4 stars
  1. <html>
  2. <head>
  3. <title>Background Color Changer</title>
  4.  
  5. <script language = JavaScript>
  6. <!--
  7. function BG_yellow()
  8. {
  9. document.bgColor = 0xFFFF00
  10. }
  11.  
  12. function BG_thistle()
  13. {
  14. document.bgColor = 0xD8BFD8
  15. }
  16.  
  17. function BG_plum()
  18. {
  19. document.bgColor = 0xDDA0DD
  20. }
  21.  
  22. function BG_red()
  23. {
  24. document.bgColor = 0xFF0000
  25. }
  26. //-->
  27. </script>
  28.  
  29. </head>
  30. <body >
  31.  
  32. <center>
  33. <form>
  34. <font face="comic sans ms">
  35. <br>
  36. <h1>
  37. Set the background color
  38. </h1>
  39. <br>
  40. <input type = button value = "Make background Yellow " onclick = "BG_yellow()">
  41. <br>
  42. <br>
  43. <input type = button value = "Make background Thistle" onclick = "BG_thistle()">
  44. <br>
  45. <br>
  46. <input type = button value = "Make background Plum " onclick = "BG_plum()">
  47. <br>
  48. <br>
  49. <input type = button value = "Make background Red " onclick = "BG_red()">
  50. </font>
  51. </form>
  52. </center>
  53.  
  54. </body>
  55. </html>
  56.  
Comments (Newest First)
Mohan0704 | Newbie Poster | May 20th, 2008
Next time,
Try make the webpage XHTML 1.1/1.0 compliant.

It's much easier to read and will prevent browser errors.
fai_zal1 | Newbie Poster | Mar 8th, 2006
very good
TechnoLady | Newbie Poster | Oct 22nd, 2005
TechnoLady

Am learning more from you than 1 year at college. Great work.
damondash | Unverified User | Aug 25th, 2005
nice Keep it up
techy | Newbie Poster | Jul 15th, 2005
Good
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 7:36 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC