如果选择了一个单选按钮,我正在尝试使用 if else 语句执行某个操作,如果选择了另一个单选按钮,则执行不同的操作。在这种情况下,如果选择了基本按钮,我想使用一个公式,如果选择了专业按钮,我想使用专业公式。我是编程新手,所以提前道歉。
<html>
<head>
<title>Calculator</title>
<script language="javascript" type="text/javascript">
function packageTotal(){
//Enter in prices here
var x = 5;
var y = 10;
var p = x + y*12;
var b = y * 12;
if(document.calculator.getElementById('basicProgram').checked) {
//Basic package is checked
document.calculator.total.value=b;
}else if(document.calculator.getElementById('proProgram').checked) {
//Pro package is checked
document.calculator.total.value=p;
}
</head>
<body>
<!-- Opening a HTML Form. -->
<form name="calculator">
<!-- User fills out form here -->
<br />
<input type="radio" name="programType" id="basicProgram" value="Basic" /> Basic
<input type="radio" name="programType" id="proProgram" value="Pro" checked /> Pro
<!-- Here result will be displayed. -->
<br />
Your total price is: <input type="text" name="total">
<input type="button" value="Submit" onclick="javascript:packageTotal();">
</form>
</body>
</html>