My code is using a canvas that allows people to draw whatever they want, what I’m trying to implement is changing the color of what their coloring on button click, default color is black I have two buttons to change ot red and green and also a clear canvas button, none of these seems to operate on button click however.
<h3>Draw Something</h3>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Paint Canvas</title>
<style type="text/css">
<!--
#container { position: relative; }
#imageView { border: 1px solid #000; }
-->
</style>
</head>
<body>
<div id="container">
<canvas id="imageView" width="600" height="300">
</p>
</canvas>
</div>
<script type="text/javascript" src=".js"></script>
</html>
<body >
<input type= "button" value= "Green" id= "green" onclick= "GreenRect()" />
<input type= "button" value= "Red" id= "red" onclick= "RedRect()" />
<input type= "button" value= "clear canvas"
id= "clear" onclick= "ImgClr()" />
<button id="howdy">Howdy!</button><br>
</body>
function GreenRect () {
context.strokeStyle= 'green';
context.stroke();
}
function RedRect () {
context.strokeStyle= 'red';
context.stroke();
}
function ImgClr () {
context.clearRect(0,0, 600, 300);
}
</script>
You did have a lot of mis-formed html, like a second
<body>tag as well as a</html>half way through your code, either of which would have completely confused a browser as you can see by Firefox’s noble attempt to make sense of your code:Also there is:
<h3>tag outside of your<body>tag<body>and<head>tags as well as lacking an opening<script>tag.<p></p>tags within your canvas tags that don’t seem to be doing anything.I’d strongly recommend not looking at my code below, but first just trying to clean up your html according to the comments I’ve made about it. I think you would get a lot out of doing that for yourself.