You'll need to correct those comparison operators as obliq says. Your getInputValue function was not included. However, the following works:
Code:
<!DOCTYPE HTML>
<head>
<title>Test</title>
<script type="text/javascript">
function getInputValue() {
var radioObj = document.forms["myForm"]["colorc"];
for (var i=0; i<radioObj.length; i++) {
if (radioObj[i].checked)
return radioObj[i].value;
}
alert("No radio button was selected.")
}
function change_it() {
var a = getInputValue();
if(a=="blue") {
document.body.style.background=a
return false;
} else if(a=="red") {
document.body.style.background=a
return false;
} else if(a=="yellow") {
document.body.style.background=a
return false;
}
}
</script>
</head>
<body>
<form name="myForm">
<input type="radio" name="colorc" value="blue">blue <br>
<input type="radio" name="colorc" value="red">red <br>
<input type="radio" name="colorc" value="yellow">yellow <br/> <br />
<input type="button" value="changecolor" name="ChangeColor" onclick="return change_it()">
</form>
</body>
</html>
Bookmarks