I have two text fields, one represents a percentage and the second represents a corresponding amount. Now what I want is, when the percentage changes the amount should change and when the amount changes the percentage should change accordingly. I am using javascript.
In this case, if any of them changes an infinite loop will start.
What I would like is that when the amount changes, it should change the percentage accordingly and then the loop should stop. And when the percentage changes, it should change the amount accordingly and then the loop should stop. Is there any way for this? Maybe something like stopPropagation
?
Dummy JS Code:
Here value
is one text box and percentage
is another text box
function valueChng(){
percentage.value = "" + someInteger;
}
function percentageChng(){
value.value = "" + someInteger;
}
Thanks!!
I still don't see a problem here, as a change handler is not executed when the content is changed programmatically. I just implemented a simple fiddle to show how it is working without running into in infinite loop (using jquery for simplicity): http://jsfiddle.net/aWuks/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With