JavaScript Question
Posted: Thu Nov 06, 2008 5:09 pm
I started learning JavaScript by myself, basing my scripts on my knowledge of HTML and basic knowledge of Python and Java.
However, when you click the button, it changes the background to black. When you click it again, it is supposed to go back to white. However, it goes white 1 sec, and then back to black.
EDIT: After reading my code carefully, I managed to think that it is quite logical. It changes the color to white, but the script says that it has to change it back to black if it's white. How do I stop the website after it executed the else command?
Thanks!
Here's the script:
However, when you click the button, it changes the background to black. When you click it again, it is supposed to go back to white. However, it goes white 1 sec, and then back to black.
EDIT: After reading my code carefully, I managed to think that it is quite logical. It changes the color to white, but the script says that it has to change it back to black if it's white. How do I stop the website after it executed the else command?
Thanks!
Here's the script:
Code: Select all
<html>
<head>
<title>H1ome</title>
<SCRIPT language="JavaScript">
<!--
function changecolor()
{
if(document.bgColor='white')
{
document.bgColor='black';
}
else
{
document.bgColor='white';
}
}
//-->
</SCRIPT>
</head>
<body>
Clicking this button will change the background color to black.
Clicking it again will change it back.
<FORM>
<INPUT type="button" value="click" name="button01" onClick="changecolor()">
</FORM>
</body>
</html>