These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

enable textfield based on radio button slection

smilem
Registered: Apr 1 2008
Posts: 101
Answered

I'm trying to do enable disable textfield based on radio button selection. I have 2 radio buttons.

if radiobutton 1 on

then textfield1 writable

else

textfield1 read only
textfield 2 writeable

end;

Should I put the code on radiobutton 1 or radiobutton 2? Or on the RadioButtonList?

My Product Information:
LiveCycle Designer, Windows
smilem
Registered: Apr 1 2008
Posts: 101
I Made this code but the else part never fires

radio button 1 mouseup event

if (this.rawValue == 1) {

vardas_pavarde.access = "readOnly";
vardas_pavarde.ui.oneOfChild.border.fill.color.value = "255,249,203"; // yellow
}
else {
vardas_pavarde.access = "open";
vardas_pavarde.rawValue = null; //field reset
vardas_pavarde.ui.oneOfChild.border.fill.color.value = "255,255,255"; // colorreset
}radio button 2 mouseup event

if (this.rawValue == 2) {

imones_pavadinimas.access = "readOnly";
imones_pavadinimas.ui.oneOfChild.border.fill.color.value = "255,249,203"; // yellow
}
else {
imones_pavadinimas.access = "open";
imones_pavadinimas.rawValue = null; //field reset
imones_pavadinimas.ui.oneOfChild.border.fill.color.value = "255,255,255"; // colorreset
}
jonom
Registered: Jan 31 2008
Posts: 133
The code should be on the radio button group, not the individual buttons.

I find it generally easier to use a switch() statement than if/else for this kind of thing - especially if you have a bunch of buttons in the group.

switch(this.rawValue){
case "1":
textfield1 open;
break;
case "2":
textfield1 readOnly;
textfield2 open;
break;
default:
put default code here if needed;
}


Hope that helps!
smilem
Registered: Apr 1 2008
Posts: 101
Thanks I got it sorted.
How do I reset my "readonly" fields with form "reset button"?

Is there some general code to make writeable all form fields? Or I will have to add individual field code for every field to reset button?
jonom
Registered: Jan 31 2008
Posts: 133
A regular reset button should do the trick, but the fields' default properties would need to be set via the Object palette - if you are setting defaults via code you would have to reset via code.

You can write a loop that loops through form objects and does whatever you need.

Here's an example of one I've used, it's on the click event of a button I've used for signing a document. It goes through the form and sets everything to readOnly and then manually sets some specific fields to remain open. I'm not the originator of the code, I think I got it from the Adobe forums. The loops are quite handy and can be used for quite a bit of stuff.

// Get the field containers from each page.for (var i = 0; i < xfa.host.numPages; i++) {var oFields = xfa.layout.pageContent(i, "field");var nodesLength = oFields.length; // Set the access type.for (var j = 0; j < nodesLength; j++) {var oItem = oFields.item(j);if (oItem != this) {oItem.access = "readOnly";}}} //after setting everything readOnly I then//manually adjust certain fields access//and visibility this.access="readOnly";subSubmission.Print.access="open";subSubmission.SaveAs.access="open";subInstructions.ApplicationNumber.access="open";subInstructions.ApplicationDate.access="open";subSubmission.EmailYes.presence="visible";subSubmission.EmailNo.presence="hidden";subSubmission.EmailYes.access="open";
smilem
Registered: Apr 1 2008
Posts: 101
Thanks.