Copy link to clipboard
Copied
I'm wondering if it is possible to write a javascript to turn off another field in a PDF form if a Check Box is checked? I'm not even close on this one below. I'm trying to figure out if someone checks check box cb144 then if will rendor another field 6a unfillable. If it's unchecked then it can be filled in. Is this possible? Thank you again if anyone has any ideas on how to code this one.
var theField = this.getField("cb144");
var theValue = theField.value;
if (theValue == "Resident") {
this.getField("6a").value= "";
}
else {
this.getField("6a").value= "";
}
Assuming the export value of cb144 is "Resident", enter the following custom calculation script in field 6a:
if(this.getField("cb144").value=="Resident")
{event.target.readonly=true}
else
{event.target.readonly=false}
In JavaScript, the "or" condition is written as || . Try this:
if(this.getField("17a4a").value=="Yes" || this.getField("a17a4c").value=="Yes")
{event.target.readonly=true}
else
{event.target.readonly=false}
if(this.getField("17a4a").value=="Yes" || this.getField("a17a4c").value=="Yes" || this.getField("a17a4b").value=="Yes")
{event.target.readonly=true}
else
{event.target.readonly=false}
Copy link to clipboard
Copied
Assuming the export value of cb144 is "Resident", enter the following custom calculation script in field 6a:
if(this.getField("cb144").value=="Resident")
{event.target.readonly=true}
else
{event.target.readonly=false}
Copy link to clipboard
Copied
Wow . This works great! I really appreciate it. You are awesome.
Copy link to clipboard
Copied
Hello,
I have a follow up question to the answer you've given. As it turns out, i now have (2) check boxes, if either are checked, then it would render a field unfillable. I'm trying, without luck, to update the code to make this happen. Here is what the code ended being, followed by my attempt to add the second check box as a possible reason to make the field unfillable.
if(this.getField("17a4a").value=="Yes")
{event.target.readonly=true}
else
{event.target.readonly=false}
This is the coding i attempted and it did not work.
if((this.getField("17a4a").value=="Yes") or (this.getField("a17a4c").value=="Yes")
{event.target.readonly=true}
else
{event.target.readonly=false}
Copy link to clipboard
Copied
In JavaScript, the "or" condition is written as || . Try this:
if(this.getField("17a4a").value=="Yes" || this.getField("a17a4c").value=="Yes")
{event.target.readonly=true}
else
{event.target.readonly=false}
Copy link to clipboard
Copied
Hopefully, last question. When i enter the condition it definately turns off the field when i check the box. The only issue i'm having is if I uncheck the box, it doesn't turn the field back on. Not sure how to make this happen if it gets unchecked after it was check.
Copy link to clipboard
Copied
You would have to uncheck both under this script.
Copy link to clipboard
Copied
Bummer, that's not working. I'm just wondering if i need to think of this a different way. There a total of 3 check boxes. Wondering if i could write a script for justg the third box only which is 17a4b where if this box is check then it turns on the field to enter data into? If it is unchecked then that field "6a" is not fillable? Could this work?
Copy link to clipboard
Copied
Where is your script? Are the export values of the 2 check boxes both "Yes"?
Copy link to clipboard
Copied
Yes, both are yes. Should i change one of them to something else? Like no?
Copy link to clipboard
Copied
No. They should be Yes to match the script. I'm trying to figure out why it isn't working. Can you upload the form?
Copy link to clipboard
Copied
I really appreciate your help. I have to leave and will get back at this tomorrow. The weird thing is the script works. The problem is once i check the box in locks the field in question. If i uncheck either of the two check boxes it doesn't revert back to a fillable field. Seems like if i could write a script for justg the third box only which is 17a4b where if this box is check then it turns on the field to enter data into? If it is unchecked then that field "6a" is not fillable? By doing something like this then I only have to focus on one check box.
Copy link to clipboard
Copied
I tested it. You have to uncheck both boxes, since your script says one or the other. Check the console for errors.
Copy link to clipboard
Copied
Hot diggity! Yes, there was a slight typo. The script is PERFECT!!!! Thank you for your patience and more importantly your help.
Copy link to clipboard
Copied
Hello,
This is working perfectly! I do have one more question. As it turns out the third checkbox "17a4b" when it's checked it will also turn off certain fields, so now i need this script to work for a third scenario when checked (this result is "Yes" as well). I'm still not used to how you added the second scenario so any help with this one would be much appreciated. Thank you again for your help. You've been awesome!
if(this.getField("17a4a").value=="Yes" || this.getField("17a4c").value=="Yes") {event.target.readonly=true} else {event.target.readonly=false}
Copy link to clipboard
Copied
Is 17a4b part of the other 2 choices or is it a stand alone condition?
Copy link to clipboard
Copied
Part 17a4b is part of the other 2 choices.
Copy link to clipboard
Copied
if(this.getField("17a4a").value=="Yes" || this.getField("a17a4c").value=="Yes" || this.getField("a17a4b").value=="Yes")
{event.target.readonly=true}
else
{event.target.readonly=false}
Copy link to clipboard
Copied
It's almost there. The only question i have is when "a17a4b" is checked i would like to have fields fields remain fillable while the other two fields because disabled. The (4) fields are 5a, 6a, 7a, 8a. Everything else is perfect!
Copy link to clipboard
Copied
Checking in again. I keep playing around with the last part of the script and I just can't figure it out. I'm really hoping you can help me get this to the finish line. So far, everything has been perfect. The only question i have is when "a17a4b" is checked i would like to have fields fields remain fillable while the other two fields because disabled. The (4) fields are 5a, 6a, 7a, 8a.
Copy link to clipboard
Copied
I was just thinking more about this and realized the same script works for any of the (4) fields i mention in previous post. So, I just need to figure out one script, which i can insert into any of fields necessary. Right now if i check any of the check boxes it disables the field. I like to the script to work when "a17a4b" is checked i would like to have field remains fillable. But if one of the other two check boxes are checked then it disables the field.
Copy link to clipboard
Copied
Hi @stepheng54012748 , @PDF Automation Station
I was also testing this as a Mouse Up event script executed from the checkbox widget:
(event.target.value !== "Off") ? this.getField("6a").readonly = true : this.getField("6a").readonly = false