プロジェクトの作業。私は仕事にelse文を必要とするが、私は、送信ボタンを打ったとき、それはちょうどあなたがあなたの要素の値で動作する必要がif/elseステートメントの要素IDの取得
<head>
<script>
var judgmentAmount = document.getElementById('judgmentAmount');
var amountCollected = document.getElementById('amountCollected');
function judgmentCalc() {
if(judgmentAmount - amountCollected < 10000) {
window.open('http://afjudgment.com');
}else {
window.open('http://www.yahoo.com');
}
}
</script>
</head>
<body>
<h1>Application</h1>
<p>I understand that this application neither obligates me to <b>Affirmative Judgment</b> nor does it obligate <b>Affirmative Judgment</b> to me.</p>
<h3>Judgment Information</h3>
<form>
<span>Do you have a case number?</span>
<input type="text" name="caseNumber" />
<span>Amount of Judgment</span>
<input type="text" name="judgmentAmount" id="judgmentAmount" />
<span>Amount collected to date</span>
<input type="text" name="amountCollected" id="amountCollected" />
<input type="submit" name="submitButton" onclick="judgmentCalc();" />
</form>
だから、これをデバッグしましたか? 'var judgmentAmount'行にブレークポイントを置き、それを踏んで変数の値を調べます。期待していた値ではなく、 'HTMLInputElement'であることがわかります。これは、比較を行う前にその要素の価値を取る必要があることを警告します。 –
私の答えは、このデモを参照してください:https://jsfiddle.net/ova74kmh/。期待どおりに動作します。 –