I have something in my mind that I don’t know if its possible to achieve using javascript.
Let’s explain the scenario:
-We have input that has a number value: 1 to 100.
var myvalue = input.value; //(Lets say input has 50 as value).
var sum = {
a: myvalue,
get b() { return this.a; }
};
console.log(myvalue.a);
console.log(myvalue.b);
I’m not sure if i can explain what im trying to do
Actually when the page opens, or value changes, the console log prints on both (a,b) the same value.
My objective its:
The option a holds the new value (after the update, i.e starting at 50, and when input value changes get the new value).
The option b holds the last value (In this case will be 50, and only updates if I do manually).
Why? Because I want to do something like this:
if (sum.a != sum.b) {
//do something
sum.b = sum.a //Update the option B to the new value for next call.
}
var a = input.value
var b = input.value
console.log(a,b)
document.getElementById('valuefield').addEventListener('change', function() {
//New Value cannot be old value, or change would not have fired.
//Do Something
b = a;
a = input.value;
console.log(a,b);
});
Thank you @m_hutley that should work very good, but my point is what if there’s no input and it’s a global variable that holds a number?
I should ask that better because I’m more interested in how to do that scenario using a global variable number than a field because I’m finding most of the cases need to figure out how to play with the data changes.