Print Page | Close Window

Complusory field based on either 1 or 2 of the che

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: PDF Forms and FDF
Forum Description: This conference is for users of PDF Forms, JavaScript and FDF Toolkits.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=3975
Printed Date: 21 Oct 2019 at 9:08pm
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: Complusory field based on either 1 or 2 of the che
Posted By: ShineyS
Subject: Complusory field based on either 1 or 2 of the che
Date Posted: 12 Apr 2018 at 12:10pm
I have inserted javascript into my 2 checkboxes to make a text field complusory if either 1 or 2 of the checkboxes are checked. The problem is if I check both checkboxes and then decide to remove one of the checks, the text field is no longer compulsory because I've unchecked one of the checkboxes.
How do I code it to keep it compulsory if one of the two boxes are still checked even though ive unchecked one.
Thanks for help.



Replies:
Posted By: gkaiseril
Date Posted: 14 Apr 2018 at 12:39am
What code have you used to make the field compulsory?

Is the code different for each check box?

In what action have you placed the code?

Since you are using a custom script, user written, you may need to provide a more detailed description of the situation.




Posted By: ShineyS
Date Posted: 14 Apr 2018 at 1:05am
Thanks. I have added the code on Mouse Up action, to add the following Javascript on each of my two checkboxes:

First checkbox :
var f = this.getField("history details");
f.display = display.visible;
var v = event.target.value;
if (v != "Off") {
    f.required = true;
}
else {
    f.required = false;   
}

Second checkbox:
var f = this.getField("history details");
var v = event.target.value;
f.required = false;
if (v != "Off") {
    f.display = display.hidden;
    this.resetForm([f.name]);
}
else {
    f.display = display.visible;   
}

Thanks heaps.


Posted By: gkaiseril
Date Posted: 18 Apr 2018 at 2:19am
For each check box, you need to test the value of the other check box before clearing the required property unless you want to make the check boxes mutually exclusive of each other.

Assuming the check box fields are named "Check Box1" and "Check Box2", the mouse up scripts for both check boxes could be:

var CheckBox1 = "Check Box1"; //field name for check box 1;
var CheckBox2 = "Check Box2"; // field name for check box 2;
var OtherCheckBox = CheckBox1;
if(event.target.name == CheckBox1) OtherCheckBox = CheckBox2;

var f = this.getField("history details");
if (event.target.value == "Off" && this.getField(OtherCheckBox).value == "Off") {
    f.required = false;
    f.display = display.hidden;
    this.resetForm([f.name]);
}
else {
f.required = true;
    f.display = display.visible;

}

Note the script adjust the script for the other check box'a name.





Posted By: ShineyS
Date Posted: 18 Jul 2018 at 1:50am
That worked perfectly thank you.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net