Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop down select refresh

Status
Not open for further replies.

evr72

MIS
Dec 8, 2009
265
US
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
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);
}
 
There are so many unknowns as there's so much you haven't told us (e.g what is Runner, what does your form look like, when are the functions called, what is passed into them, etc), so the following is purely guesswork:

While you seem to be adding validation rules with calls to "addValidation", you are never clearing or removing them when you change from "Yes" to "No" or vice versa. Perhaps this is the missing step?

Hope this helps,

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
As Dan points out we have no idea what your functions do, we can tell you that nowhere in your code are you removing the requirements for "yes" fields when "no" is selected. Or viceversa.

Do you have a removeValidation() function or can addValidation() support other parameters such as "isNotRequired".





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Dan and Phil,
This is for a form created with asprunner, by playing around with various scripts I came up with this one that works for the various validations, but to be honest not sure how to removeValidation() function or can addValidation(). I searched the interenet and put the scripts together, but not sure how to write one. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top