BTEC IT Unit 20 - Website Design/JavaScript/Radio Buttons
Choose input (Radio buttons)
<body>
<p>Choose your favourite colour!</p>
<form>
<input type="radio" name="colour" value="blue" onclick="myFunction()">Blue<br>
<input type="radio" name="colour" value="red" onclick="myFunction()">Red<br>
<input type="text" id="result" size="50">
</form>
<script>
function myFunction() {
var colour = document.forms[0];
var txt = "";
var i;
for (i = 0; i < colour.length; i++) {
if (colour[i].checked) {
txt = txt + colour[i].value + " ";
}
}
document.getElementById("result").value = txt + "...such a nice colour";
}
</script>
</body>
</html>