我一直在创建一个表格,客户可以输入他们的院子大小并获得报价。如果我只使用一个没有的公式,否则它工作正常,但当我添加其他公式选项来创建准确的定价时,我得不到任何结果。我已经阅读了多个建议并尝试了任何我可以罚款但无济于事。
<head>
<title>Test</title>
</head>
<body>
<form name="Instant Quote">
<table border="1" width="300" height="200" cellpadding="10" cellspacing="3">
<tr>
<th colspan="2">
<h1>Instant Quote</h1>
</th>
</tr>
<tr>
<th>
<h3>Square Footage of Yard</h3>
</th>
<th>
<input type="number" name="INPUT1" id="input" onchange="calculate();"/>
</th>
</tr>
<tr>
<th>
<h3>Cost per treatment</h3>
</th>
<th>
<input type="number" name="OUTPUT1" id="output">
</th>
</tr>
<tr>
</tr>
</table>
</form>
<script type="text/javascript">
function calculate() {
var USERINPUT1 = document.TESTING.INPUT1.value,
if (USERINPUT1 >=0 && USERINPUT1 <= 5000) {
RESULT = (USERINPUT1*.005) + 25;
} else if (USERINPUT1 >=5001 && USERINPUT1 <= 10000) {
RESULT = (USERINPUT1*.0045) + 25;
} else {
RESULT = (USERINPUT1*.004) + 25;
}
document.TESTING.OUTPUT1.value = RESULT;
}
</script>
<body>
答案 0 :(得分:0)
function calculate() {
var USERINPUT1 = document.getElementById("input").value;
if (USERINPUT1 >=0 && USERINPUT1 <= 5000) {
RESULT = (USERINPUT1*.005) + 25;
} else if (USERINPUT1 >=5001 && USERINPUT1 <= 10000) {
RESULT = (USERINPUT1*.0045) + 25;
} else {
RESULT = (USERINPUT1*.004) + 25;
}
document.getElementById("output").value = RESULT;
}
<form name="Instant Quote">
<table border="1" width="300" height="200" cellpadding="10" cellspacing="3">
<tr>
<th colspan="2">
<h1>Instant Quote</h1>
</th>
</tr>
<tr>
<th>
<h3>Square Footage of Yard</h3>
</th>
<th>
<input type="number" name="INPUT1" id="input" onchange="calculate();"/>
</th>
</tr>
<tr>
<th>
<h3>Cost per treatment</h3>
</th>
<th>
<input type="number" name="OUTPUT1" id="output">
</th>
</tr>
<tr>
</tr>
</table>
</form>