Copy link to clipboard
Copied
I have an order entry form that calculates a markup $ amount by a formula in the simplified field notation section in the field properties of the calculate tab. The Markup field is set to read only. I also have a field setup as a check box. If the user selects that check box, I need that markup field to become editable (remove the read only attribute) to allow a number to be entered in the field. I am assuming I would also need to programmatically remove the calculation in the simplified field notation when the check box has been selected. I am thinking I need a custom java script to trigger on mouse enter? I also could use some help setting up the java script. Has anyone every done something similar?
Thanks in advance.
1 Correct answer
You won't be able to use the "simple field notation" method anymore if you need to make the field editable in certain situations. The following script assumes that you just want to add up two fields and use 25% of that sum as your markup, unless the checkbox named "CheckBox" is checked, then the field will become editable, and you can enter anything you want:
...// get the state of the "CheckBox" - modify the field name to match your form
var cb = this.getField("CheckBox");
if (cb.value == "Off") {
Copy link to clipboard
Copied
You won't be able to use the "simple field notation" method anymore if you need to make the field editable in certain situations. The following script assumes that you just want to add up two fields and use 25% of that sum as your markup, unless the checkbox named "CheckBox" is checked, then the field will become editable, and you can enter anything you want:
// get the state of the "CheckBox" - modify the field name to match your form
var cb = this.getField("CheckBox");
if (cb.value == "Off") {
// Checkbox is unchecked, so perform the calculation and make sure the field is read-only
event.target.readonly = true;
// simple calculation - you need to modify this
var result = (Number(this.getField("Field1").value) + Number(this.getField("Field2").value)) * 0.25;
event.value = result;
}
else {
// Checkbox is checked, so do not modify the value, set the field to read/write and let the user enter anything they want.
event.target.readonly = false;
}
Copy link to clipboard
Copied
Thanks for the code. Would you enter this code in the custom calculation script or as an action in the markup field or the actual checkbox? I really appreciate the help.
Copy link to clipboard
Copied
Sorry, I should have clarified that: It's the custom calculation script of your result field.
Copy link to clipboard
Copied
Working perfectly now. Thank you for the help.

