Copy link to clipboard
Copied
hi everyone,
I need help on Acrobat, I made a script, it works, but when I save it doesn't work anymore.
my code :
var checkBox1 = this.getField('companyLogoonsignage');
checkBox1.setAction('MouseUp', 'validate(checkBox1, "total2")');
function validate(field, formTextField) {
if (field.isBoxChecked(0)) {
this.getField(formTextField).value = '80';
}
else {
this.getField(formTextField).value = '0';
}
}
pose here
after backup
error
I have some sort of code compression and it doesn't work anymore so how do I keep my code as it is, if you have any improvements for the code, I take it.
sorry for my poor English
Copy link to clipboard
Copied
You should not include the setAction command in your script. This only needs to execute once (if at all), and it won't work in Reader. Also, the "validate" function should be defined either under the field where it's being called, or (better yet) as a doc-level script.
Copy link to clipboard
Copied
Set the field as read-only to block the user from changing its value.
Copy link to clipboard
Copied
You should not include the setAction command in your script. This only needs to execute once (if at all), and it won't work in Reader. Also, the "validate" function should be defined either under the field where it's being called, or (better yet) as a doc-level script.
Copy link to clipboard
Copied
Can you show me how to do it, because I don't understand where I have to go.
Copy link to clipboard
Copied
You'll need to explain first what you're trying to achieve, exactly. What does the check-box has to do with the validation of the "total2" field? If you want the value of the text field to be dependent on that of the check-box use a Calculation script, instead. Then it will execute each time any field in the file (including the check-box) is edited.
Copy link to clipboard
Copied
So do the final totals no problem: properties > calculation > the value corresponds to/to the sum(+) > checked all the boxes I need
I know how to do addition and multiplication, but I don’t know how to block the possibility for a user to change a number field. Do you have any solutions for me?
Copy link to clipboard
Copied
Set the field as read-only to block the user from changing its value.
Copy link to clipboard
Copied
It blocks me all fields me, I need some fields not all.
Copy link to clipboard
Copied
You need to be more specific. The read-only property applies to each field separately.
What exactly did you do, and what was the result?
Copy link to clipboard
Copied
so I clicked on lock in the properties and it blocked all the fields, while I want to do as on my document above
Copy link to clipboard
Copied
Lock and Read-Only are not the same thing. And don't do it for all fields, if you only want to block some...
Copy link to clipboard
Copied
Thanks, I didn't understand while translating.
And for the original problem did you have a solution?
Copy link to clipboard
Copied
Yes, I already answered that. See above.
Copy link to clipboard
Copied
So sorry, I expressed myself badly could you show me an example, because I don't understand sorry, I'm a beginner.
Do you have any screenshots so that I can visually understand how to do it in the software? 😞
Copy link to clipboard
Copied
Is the purpose of your code simply to populate a text field with "80" if a certain check-box is ticked, and with "0" if it's not ticked? Do you need to apply the exact same code for multiple text fields, just based on different check-boxes, or only for one?
Copy link to clipboard
Copied
Overall yes I just want when I check the box at the end of the line in my field it writes 80 and when it doesn't check nothing or 0. And there will be other boxes but not with the same numbers and not the same fields.
Copy link to clipboard
Copied
You don't need a function for that, or most of the rest of your code, either.
Just use the following as the custom Calculation script of the text field:
event.value = (this.getField("Checkbox1").isBoxChecked(0)) ? 80 : 0;
Adjust the name of the check-box field in the code as needed.
Copy link to clipboard
Copied


So, thank you, it almost works, there is a weird thing it acts like a subtraction on my final total which is a sum of all the fields at the end of the line, I find it doesn't make sense?
Copy link to clipboard
Copied
Check the fields calculation order. Make sure the total field is at the end of the list.
Copy link to clipboard
Copied
This is where it comes into play. Sorry I do not understand
Copy link to clipboard
Copied
In Prepare Form mode click on More and then on Set Fields Calculation Order.
Copy link to clipboard
Copied
thank you so much you are my hero 😄
Copy link to clipboard
Copied
Where does you use the script?
Why doesn't you define the function at document level?