Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Complusory field based on either 1 or 2 of the che
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Complusory field based on either 1 or 2 of the che

 Post Reply Post Reply
Author
ShineyS View Drop Down
New Member
New Member


Joined: 12 Apr 2018
Location: Aus
Points: 4
Post Options Post Options   Quote ShineyS Quote  Post ReplyReply Direct Link To This Post Topic: Complusory field based on either 1 or 2 of the che
    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.
Back to Top
Sponsored Links


Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4101
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post 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.




Edited by gkaiseril - 14 Apr 2018 at 12:40am
Back to Top
ShineyS View Drop Down
New Member
New Member


Joined: 12 Apr 2018
Location: Aus
Points: 4
Post Options Post Options   Quote ShineyS Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4101
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post 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.



Back to Top
ShineyS View Drop Down
New Member
New Member


Joined: 12 Apr 2018
Location: Aus
Points: 4
Post Options Post Options   Quote ShineyS Quote  Post ReplyReply Direct Link To This Post Posted: 18 Jul 2018 at 1:50am
That worked perfectly thank you.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.063 seconds.