Search guided me to the following thread:
How to set value in Choice field based on value of other choice field
Following the instructions there I did the following:
1. Set JavaScript variables for Checkbox and Dropdownlist:
2. Edit and copy JavaScript into Settings / custom javascript:
NWF.FormFiller.Events.RegisterAfterReady(function () {
NWF$('#'+varcheckboxYes).change(function(){
if (NWF$('#'+varcheckboxYes+ ' input:checked').val() == 'Yes'){
NWF$('#'+vardropdown).val('Yes');
}
});
});
Unfortunately this still does not work.
input:checked selector works for radio button but not for yes/no control/checkbox.
for checkbox you have to use
NWF$('#'+varcheckboxYes).prop('checked')
Hi Michael,
I had a look at your question and have your fix! On the form I have a Yes/No choice field and Yes/No dropdown list connected to a column:
I ran this script in the Custom Javascript of the Form Settings and validated that it works!
NWF$("#"+yesnocheckbox).click(function(){
if(NWF$(this).prop("checked")){
NWF$("#"+yesnochoicefield).val("Yes");
}
else{
NWF$("#"+yesnochoicefield).val("No");
}
})
Let me know if you can't get this working!
Cheers,
Scott
Hi Scott,
First of all thanks a lot for your time.
I re-build your approach, I am able to publish it, but it won't open, neither in preview, nor live (loading endless "please wait"......)
This is what I did:
Settings checkbox:
Settings dropdown-choice list:
Custom JavaScript Settings:
I cannot detect any error.
Best regards
Michael
have you checked developer console for any errors?
I would suggest to stick with onchange event handler as in your former script.
onclick event handler just captures mouse clicks, so if you change checkbox status by other ways (keyboard,....) it will not fire your handler.
I have it now:
NWF$("#"+yesnocheckbox).click(function(){
if(NWF$(this).prop("checked")){
NWF$("#"+yesnochoicefield).val("Yes");
}
else{
NWF$("#"+yesnochoicefield).val("No");
}
});
There was only a semicolon missing at the end of the script.
Thanks to all!
Scott Carnegie,
Can i use multiple if and else if i have numerous checkboxes and choice columns. How would i change the code?
Hi All! I am trying to do the same type of code but for when two check boxes have been checked. Can you assist me with this??
Matt P.
Not sure if you or anyone else can answer this, I have this setup and is working as advertised. However, I have a rule setup that unhides a panel when the drop down is set to Yes. When I select my checkbox and the drop down becomes "yes" the panel does not display. However if I change the drop down to No then back to Yes, the panel appears. Any thoughts?
Ok I worked on it a few times and I was able to figure this out. I had to change my rule to evaluate the control a little differently. I needed to show a panel when the choice control is equal to "Yes". When the yes/no checkbox was checked, the JS ran and changed the value in the choice control to "Yes" like I wanted. Apparently there must be some sort of click requirement for the rule to fire against my choice control. So I added the rule to include whether or not the yes/no checkbox was selected. I also needed the rule to evaluate if the choice control was "Yes" because there were circumstances where that could still happen. So here is my rule
or(Expense!="Yes" && not(Opportunity), Expense!="Yes")
Expense = Choice Control (drop down list)
Opportunity = Yes/No check box.
Does this still work with 4 different checkboxes?
Depending on which of the four checkboxes are selected will determine which of the four choices will be selected in the choice field.
Or am I better have two choice fields; one with the 4 possible selections and the other with an outcome based on the first choice field?
Sorry, I am very new to Nintex so am still getting my head around it.