Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-09-2005, 03:57 PM   PM User | #1
hull
New to the CF scene

 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
hull is an unknown quantity at this point
JavaScript button to change background colors

I am new to JavaScript. As a student we are given projects and I cannot for the life of me figure this one out. I am to use the a simple document object, specifically document.bgColor, to create one button that directs the user to click to change background color. I can change color fine but not to change the color back. The rub here is only to use one button and to keep it simple. If anyone can help me I would be eternally grateful. Thank You in advance

Last edited by hull; 03-09-2005 at 07:53 PM.. Reason: wrong document object
hull is offline   Reply With Quote
Old 03-09-2005, 03:59 PM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
can u show us what you have done so far? (we usualy don't do other's homework, but we might help you to correct it )
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 03-09-2005, 06:58 PM   PM User | #3
hull
New to the CF scene

 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
hull is an unknown quantity at this point
Yes, I can show you what I have here at work I have some code at home that does not execute either. First I have this that works only one click.
now I tried to add some var but it did not execute. so I have left what does work and I feel I am just missing something. To correct an error It is document.bgColor sorry about that.

<HTML>
<head>
<title>color change once</title>
<script language="JavaScript">
<!--
function newbg (difcolor)
{
document.bgColor=difcolor;
}
//-->
</script>
</head>
<body bgColor="yellow">
<b>Stop looking at this horrible color! Click the button, Change the color.</b>
<p>
<input type="button" value="Change Color" OnClick="newbg('lightblue');">

</body>
</HTML>

Then I tried this:

<HTML>
<head>
<title>background Colors</title>
<script language="JavaScript">
<!--
function switchcolor()
{
if (document.bgColor=="yellow")
{
document.bgColor="lightblue";
}
else
{
if (document.bgColor=="lightblue")
{
document.bgColor="yellow";
}
}
}
//-->
</script>
</head>
<body bgColor="yellow">
<b>Want a new background color? Click the Button!</b>
<p>
<form>
<input type="button" value="Change Color" onClick="switchcolor();">
</form>

</body>
</HTML>

and this does not work at all. This is an intro course so I want to keep it simple. I am really just looking for suggestions as to what direction to move. I am new to JS and Forums too so any help is appreciated.

Hull
hull is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:36 AM.


Advertisement
Log in to turn off these ads.