This solution works, the problem is when the user clicks on submit the item being drawn just keeps overlapping the last one. So I can click on the halfcircle radio button and then the quadratic curve and they just overlap one another.
How could I mkae it so the items dont overlap and only one is shown at a time
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<form>
<input type="radio" name="radio" id="rd1" value="Show Arc" checked="checked"/>Show Arc<br>
<input type="radio" name="radio" id="rd2" value="Show Half Circle"/>Show Half Circle<br>
<input type="radio" name="radio" id="rd3" value="Show Circle"/>Show Circle<br>
<input type="radio" name="radio" id="rd4" value="Show X"/>Show X<br>
<input type="radio" name="radio" id="rd5" value="Show Quadratic Curve"/>Show Quadratic Curve<br><br>
<input type="submit" id="button" value="Submit"/>
</form>
<canvas id="canvas" width="500" height="500">
Get a new browser
</canvas>
<script src="Lesson3.js"></script>
</body>
</html>
JS
var button = document.getElementById('button');
var rd1 = document.getElementById('rd1');
var rd2 = document.getElementById('rd2');
var rd3 = document.getElementById('rd3');
var rd4 = document.getElementById('rd4');
var rd5 = document.getElementById('rd5');
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
button.addEventListener('click', function(){
if(rd1.checked){
showArc();
}
else if(rd2.checked){
showHalfCircle();
}
else if(rd3.checked){
showCircle();
}
else if(rd4.checked){
showX();
}
else if(rd5.checked){
showQuadraticCurve();
}
else{ alert('nothing to show');
}
}, false);
function showArc(){
context.beginPath();
context.arc(250,250,200,Math.PI/180*90,Math.PI/180*270,false);
context.stroke();
}
function showHalfCircle(){
context.beginPath();
context.arc(250,250,200,Math.PI/180*90,Math.PI/180*270,false);
context.closePath();
context.stroke();
}
function showCircle(){
context.beginPath();
context.arc(250, 250, 200, 0, Math.PI*2, true);
context.closePath();
context.fill();
}
function showX(){
context.beginPath();
context.moveTo(0,0);
context.lineTo(500,500);
context.stroke();
context.moveTo(500,0);
context.lineTo(0,500);
context.stroke();
}
function showQuadraticCurve(){
context.beginPath();
context.moveTo(130,130);
context.quadraticCurveTo(150.8, 130, 160.6, 150.5);
context.quadraticCurveTo(190, 250, 210.5, 160.5);
context.quadraticCurveTo(240, 100.5, 290, 70.5);
context.stroke();
}