Hello,
I have a JavaScript for a dropdown box that checks my required fields.
All works well, the issue is that if the uers selects "Yes"
some fields are required, then let's say that the user changes its mind and chooses "No" What I was expecting to happen is that the "No" fields woudl be required.
What happens is if the user Picks "Yes" the users gets the required fields for "Yes" then if the user picks "No" then the user gets the required fields for "Yes" plus the "No" fields
The only way that I can make it work is if I refresh the page. would there be any other way for this to work?
Here is the script that I am using
I have a JavaScript for a dropdown box that checks my required fields.
All works well, the issue is that if the uers selects "Yes"
some fields are required, then let's say that the user changes its mind and chooses "No" What I was expecting to happen is that the "No" fields woudl be required.
What happens is if the user Picks "Yes" the users gets the required fields for "Yes" then if the user picks "No" then the user gets the required fields for "Yes" plus the "No" fields
The only way that I can make it work is if I refresh the page. would there be any other way for this to work?
Here is the script that I am using
Code:
function OnPageLoadEdit(pageid)
{
var tName = 'answers';
var ctrlkeycontrol = Runner.getControl(pageid, 'keycontrol');
var ctrlresp = Runner.getControl(pageid, 'resp');
var ctrlexplain= Runner.getControl(pageid,'explain');
var ctrliscontroldocumented= Runner.getControl(pageid,'iscontroldocumented');
var ctrlnarrativeofcontrol= Runner.getControl(pageid,'narrativeofcontrol');
var ctrlfrequency= Runner.getControl(pageid,'frequency');
var ctrlpersonresponsable= Runner.getControl(pageid,'personresponsable');
var ctrlmanualorautomated= Runner.getControl(pageid,'manualorautomated');
var ctrlcorrectiveactionplanned = Runner.getControl(pageid, 'correctiveactionplanned');
var ctrlplancompletiondate = Runner.getControl(pageid, 'plancompletiondate');
if (ctrlkeycontrol.getValue() == 'X'){
ctrlresp.addValidation("IsRequired");
}
function func() {
if ((ctrlresp.getValue() == 'Yes')&&(ctrlkeycontrol.getValue() == 'X')){
ctrlresp.addValidation("IsRequired");
ctrliscontroldocumented.addValidation("IsRequired");
ctrlnarrativeofcontrol.addValidation("IsRequired");
ctrlfrequency.addValidation("IsRequired");
ctrlpersonresponsable.addValidation("IsRequired");
ctrlmanualorautomated.addValidation("IsRequired");
}
else if((ctrlresp.getValue() == 'No')&&(ctrlkeycontrol.getValue() == 'X')){
ctrlcorrectiveactionplanned.addValidation("IsRequired");
ctrlplancompletiondate.addValidation("IsRequired");
}
else if((ctrlresp.getValue() == 'Other')&&(ctrlkeycontrol.getValue() == 'X')){
ctrlresp.addValidation("IsRequired");
ctrlexplain.addValidation("IsRequired");
ctrliscontroldocumented.addValidation("IsRequired");
ctrlnarrativeofcontrol.addValidation("IsRequired");
ctrlfrequency.addValidation("IsRequired");
ctrlpersonresponsable.addValidation("IsRequired");
ctrlmanualorautomated.addValidation("IsRequired");
}
else if ((ctrlresp.getValue() == 'N/A')&&(ctrlkeycontrol.getValue() == 'X')){
ctrlexplain.addValidation("IsRequired");
}
};
ctrlresp.on('change', func);
ctrlkeycontrol.on('change', func);
ctrlresp.on('change', func);
ctrlkeycontrol.on('change', func);
}