Multiplying a Text Field if a Checkbox is Checked, while freely being able to Uncheck it.
I want to have a text field, "MA", with an initial value typed into it ("10"). When a seperate checkbox is checked ("CRITICAL1"), I want the value in MA to be halved ("5"). The script I wrote does that, but I'd also like those changes to revert when the box is unchecked. As it works now, unchecking the box does not change MA back to 10 from 5, and a subsequent recheck would halve MA again to sqrt(5).
The script below is a fix I tried to implement, where I multiply by 2 when the box is unchecked to cancel out the halving, but I've ran into a different problem where the initial number I input into MA is doubled from the start (e.g. when filling out MA for the first time, I write "10" and it becomes "20"). It's important to the document that MA works with any input, not just the one's I've used in my example. Any help?
var v1 = this.getField("CRITICAL1").isBoxChecked(0);
function test(){
if(v1){event.value = event.target.value*0.5;}
else{event.value = event.target.value*2}
}