javascript で次のことを行う方法を知りたい: データベースに格納されている値 (float) を持つフォームのフィールドを持っています。それをイニシャルと呼びましょう。ユーザーがこのフィールドの値を変更するたびに、それを new と呼びましょう。フォームを送信する前に、新しい値と初期値を比較したいですか? どうすればそれを達成できますか?
乾杯
javascript で次のことを行う方法を知りたい: データベースに格納されている値 (float) を持つフォームのフィールドを持っています。それをイニシャルと呼びましょう。ユーザーがこのフィールドの値を変更するたびに、それを new と呼びましょう。フォームを送信する前に、新しい値と初期値を比較したいですか? どうすればそれを達成できますか?
乾杯
HTML が指定されていないため、input
ID がtxtInput
var initial = "someDBVal";
//assigning a change handler to your input
document.getElementById("txtInput").onchange = function() {
var newx = document.getElementById("txtInput").value;
if (newx == initial) {
alert("they match");
} else {
alert("no match");
}
}
var initial = 0.123;
document.getElementById("theinput").onchange = function() {
var _new = document.getElementById("theinput").value;
if (parseFloat(_new) == parseFloat(initial)) {
console.log("equal");
} else {
console.log("not equal");
}
}