...

View Full Version : Resolved Random Colors at Button Click



MrEnder
03-15-2010, 06:17 AM
I dont get why that doesn't work... it has me baffled 0.o



<html>
<div id="divId">Button clicked 0 times</div>
<input type="button" value="click me" onclick="divClick()" />
<script type="text/javascript">

var i = 0;

function divClick() {

var colorNum1 = Math.floor(Math.random()*255);
var colorNum2 = Math.floor(Math.random()*255);
var colorNum3 = Math.floor(Math.random()*255);
var color = "rbg(" + colorNum1 + "," + colorNum2 + "," + colorNum3 + ")";


i++;

var divId = document.getElementById("divId");
divId.style.backgroundColor = color;
divId.innerHTML = "Button clicked " + i + " times";



}

</script>
</html>


figured it out finally i had rbg instead of rgb ><



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum