Sunday, 29 September 2013

Changing the background color of a page

Changing the background color of a page

I am trying to make a command line, where when you type a command, such as
'bg green', the background turns green. Everything works okay except for
when you type 'bg green', and press enter, nothing happens. The background
stays black. This is my code:
<html>
<body style="background-color:black" id="a">
<div style="width:100%;bottom:0px;height:30px;position:absolute;"></div>
<div id="commandline" onkeydown="if (event.keyCode == 13) command(); "
style="-webkit-transform:rotate(0deg);font-family: 'Kelly Slab',
cursive;z-index:2;background-color:black;height:36px;width:100%;bottom:0px;position:absolute;color:white;left:0px;font-size:20px;">
&gt
<input style="font-family:'Kelly
Slab';color:white;height:100%;width:100%;background-color:black;border:none;position:absolute;font-size:30px;left:20px;top:0px;"
id="cmdinput"></input>
<div id="commands"
style="z-index:1;background-color:black;height:100%;width:100%;bottom:36px;position:absolute;left:0px;"></div>
</body>
</html>
<script type="text/javascript">
function command(){
if(document.getElementById('cmdinput').value.substring(0,9) == "bg green"{
document.getElementById('a').style.backgroundColor = 'green';
}
}
</script>
I think the issue is with the javascript, but I'm not sure. Does anyone
know what the issue is?

No comments:

Post a Comment