Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Disabling CheckBox: JavaScript

Avatar

Former Community Member
Hi,



I'm working on a form that has a drop down list and several check boxes.



Had a scripting problem, trying to figure out if there is a script in JS to disable a check box if nothing is selected in the drop down list. Couldn't find a way to do this. But now solved it via a work-around: made the check boxes "invisible" until there was a selection in the drop down list.



So no need for follow-up.



Searching online, saw a (Windows only) PDF DRM (OwnerGuard PDF) that describes robust protection features and is in a moderate cost range: http://www.armjisoft.com.



Kind Regards,



Stephen
8 Replies

Avatar

Level 2
Try this

DropDownListName.access = "readOnly";



With Regards

Sri

Avatar

Former Community Member
Thanks, Sri.



I will try this out.



Kind Regards,



Stephen

Avatar

Former Community Member
Hi Sri,



I tried to use the readOnly access, but it did not achieve the needed result. (the readOnly access can be used to disable a check box, but my problem is finding a way to trigger this event.)



It is not the DropDownList1 that I am trying to disable. It is a number of check boxes (1-13). If no health condition is chosen from the drop down list in DropDownList1's box, then the check boxes should not operate: they should be readOnly. My problem in scripting, using JS, is that I cannot figure out how to get non-choice state in the drop down box (no choice made). I tried (in the DropDownList1's change event)



if (this.rawValue = "")

{

CheckBox1.access = "readOnly"

}



and



var sNewValue = this.boundItem(xfa.event.newText)

if (newValue) == ""

{

CheckBox1.access = "readOnly"

}



Neither script works.



Any suggestions would be appreciated.



Kind Regards,



Stephen

Avatar

Former Community Member
Hi Stephen,

In the dropdown you can put an " " item as a first item. So in the change event of the dropdown you can change the access to readOnly or open by script.



if(xfa.event.newText == " ")

c.access = "readOnly";

else

c.access = "open";



Asiye

Avatar

Former Community Member
Hi Asiye,



Thanks for your reply.



I tried placing the following as a first item in the change event of the drop down, but it did not disable the check box ( I left the other script after this, as well, so you could see it):



if(xfa.event.newText == " ")

{

CheckBox1.access = "readOnly"

}

else

CheckBox1.access = "open";

}



var sNewValue = this.boundItem(xfa.event.newText)

TextField1.rawValue = sNewValue

CheckBox7.presence = "invisible"

TextField2.rawValue = ""

else if (sNewValue == "coronary artery disease, early onset: (male) <55, (female) <65")

{

TextField2.rawValue = CAD.value;

CheckBox7.presence = "visible"

}



Kind Regards,



Stephen

Avatar

Former Community Member
Hi Stephen,

The script that I gave to you works for me. When I looked at your script, there exists some syntax errors (missing curly brace, missing ;). Your script must be as follows:

if(xfa.event.newText == " ")

{

CheckBox1.access = "readOnly";

}

else

{

CheckBox1.access = "open";

}



Try this. Also the first item of the dropdown must be one spaced string in our case.

Asiye

Avatar

Former Community Member
Hi Asiye,



Thank you for your reply and suggestions. I think the missing brackets were not in the original but were a result of a poor job of "cutting and pasting."



I tried the latest script in the change event of the drop down list, as the first item, but it did not disable the check box.



If you share an email address, I will be happy to send a working draft of the form as an attachment and you can see the challenge directly.



Again, thanks for your help.



Kind Regards,



Stephen

Avatar

Former Community Member
Stephen,

You can send email to asiyegunaydin@kgc.com.tr



Asiye