Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript New to Javascript, have a PDF form im trying to hide text boxes and radio selections. Code just hides it all

guitarguru83

New Coder
I'm sure this isnt pretty, im pretty new to Javascript, we have a PDF form and im trying to set it so the page corresponds to selections made from the drop down. Thus far the code just hides the text boxes and radio boxes regardless of what the user chooses.

JavaScript:
// Define the field names
var dropdownField = "Preferred Setup";
var textField0 = "MinimumRequirementTXT0";
var textField1 = "MinimumRequirementsTXT";
var radioField0 = "Minimum Requirements.0";
var radioField1 = "Minimum Requirements.1";
var radioField2 = "Minimum Requirements.2";
var radioField3 = "Minimum Requirements.3";
var radioField4 = "Minimum Requirements.4";

// Get the field objects
var dropdown = this.getField(dropdownField);
var text0 = this.getField(textField0);
var text1 = this.getField(textField1);
var radio0 = this.getField(radioField0);
var radio1 = this.getField(radioField1);
var radio2 = this.getField(radioField2);
var radio3 = this.getField(radioField3);
var radio4 = this.getField(radioField4);

// Add a "validate" event to the dropdown field
dropdown.setAction("Validate", "if (event.value == 'Your Organization: Stand Alone Workstation' || event.value == 'Your Organization:Client Workstation') {" + text0.name + ".display = display.visible;" + text1.name + ".display = display.visible;" + radio0.name + ".display = display.visible;" + radio1.name + ".display = display.visible;" + radio2.name + ".display = display.visible;" + radio3.name + ".display = display.visible;" + radio4.name + ".display = display.visible;} else if (event.value == 'Artel Laptop: Stand-alone laptop, software pre-installed' || event.value == 'Artel Laptop:Client laptop only (database on network), software pre-installed' || event.value == 'Artel Laptop:Nothing installed') {" + text0.name + ".display = display.hidden;" + text1.name + ".display = display.hidden;" + radio0.name + ".display = display.hidden;" + radio1.name + ".display = display.hidden;" + radio2.name + ".display = display.hidden;" + radio3.name + ".display = display.hidden;" + radio4.name + ".display = display.hidden;} else {" + text0.name + ".display = display.hidden;" + text1.name + ".display = display.hidden;" + radio0.name + ".display = display.hidden;" + radio1.name + ".display = display.hidden;" + radio2.name + ".display = display.hidden;" + radio3.name + ".display = display.hidden;" + radio4.name + ".display = display.hidden;}");
 
One thing that stands out is that you're trying to set the "display" property on each field object, but you're not actually setting it to a value. The "display" property should be set to either "display.visible" or "display.hidden" depending on whether you want to show or hide the field.

Here's an updated version of your code that should work:

Code:
// Define the field names
var dropdownField = "Preferred Setup";
var textField0 = "MinimumRequirementTXT0";
var textField1 = "MinimumRequirementsTXT";
var radioField0 = "Minimum Requirements.0";
var radioField1 = "Minimum Requirements.1";
var radioField2 = "Minimum Requirements.2";
var radioField3 = "Minimum Requirements.3";
var radioField4 = "Minimum Requirements.4";

// Get the field objects
var dropdown = this.getField(dropdownField);
var text0 = this.getField(textField0);
var text1 = this.getField(textField1);
var radio0 = this.getField(radioField0);
var radio1 = this.getField(radioField1);
var radio2 = this.getField(radioField2);
var radio3 = this.getField(radioField3);
var radio4 = this.getField(radioField4);

// Add a "validate" event to the dropdown field
dropdown.setAction("Validate", "if (event.value == 'Your Organization: Stand Alone Workstation' || event.value == 'Your Organization:Client Workstation') {" + text0.name + ".display = display.visible; " + text1.name + ".display = display.visible; " + radio0.name + ".display = display.visible; " + radio1.name + ".display = display.visible; " + radio2.name + ".display = display.visible; " + radio3.name + ".display = display.visible; " + radio4.name + ".display = display.visible; } else if (event.value == 'Artel Laptop: Stand-alone laptop, software pre-installed' || event.value == 'Artel Laptop:Client laptop only (database on network), software pre-installed' || event.value == 'Artel Laptop:Nothing installed') {" + text0.name + ".display = display.hidden; " + text1.name + ".display = display.hidden; " + radio0.name + ".display = display.hidden; " + radio1.name + ".display = display.hidden; " + radio2.name + ".display = display.hidden; " + radio3.name + ".display = display.hidden; " + radio4.name + ".display = display.hidden; } else {" + text0.name + ".display = display.hidden; " + text1.name + ".display = display.hidden; " + radio0.name + ".display = display.hidden; " + radio1.name + ".display = display.hidden; " + radio2.name + ".display = display.hidden; " + radio3.name + ".display = display.hidden; " + radio4.name + ".display = display.hidden; }");

Note that I added spaces between the semicolons and the next line of code to make the code easier to read. I also added spaces between the colons and the "display.visible" or "display.hidden" values.
 
Back
Top Bottom