Skip to main content
Nintex Community Menu Bar

Value of Multiple Radio Buttons Within a Conditional Statement

  • April 16, 2018
  • 11 replies
  • 26 views

Forum|alt.badge.img+9

What is wrong with these syntax, because it's not working?

if (NWF$('#' + Question1).find("input:checked").val("Yes")) {
   NWF$('#' + AssessmentValue).val('Completed');
}

if (NWF$('#' + Question1).find("input:checked").val()=="Yes" ) {
   NWF$('#' + AssessmentValue).val('Completed');
}

11 replies

Forum|alt.badge.img+11
  • Nintex Partner
  • April 16, 2018

Maybe a stupid question but are Question1 and AssessmentValue the values specified in each control's Advanced setting "Client ID JavaScript variable name"?


Forum|alt.badge.img+11
  • Nintex Partner
  • April 16, 2018

And, in addition to Jean-Pierre question, what kind of fields are associated to Question1 and AssessmentValue? If one of them is the "outcome" of a task, its values are numbers, non the text value associated to it..


Forum|alt.badge.img+9
  • Author
  • April 17, 2018

Yes they are.


Forum|alt.badge.img+9
  • Author
  • April 17, 2018

What I'm trying to do really is to have the script mark the AssessmentValue as "Completed" when a series of questions are answered in one or more accepted combinations. Say for e.g.

If Question1="Yes" and Question2="No" and Question3="No", or

If Question 1="Yes" and Question2="Yes" and Question3="Yes" and Question="No"

then the assessment is finished and the AssessmentValue should be "Completed".

I'm not sure how to do this via JQuery so any help will be appreciated. Looking at my initial script below...I think an array for all the questions is required at some point?

NWF$('#' + Question1).click(function() {
if (NWF$('#' + Question1).find("input:checked").val("Yes")) {
NWF$('#' + AssessmentValue).val('Completed');
}
})


Forum|alt.badge.img+11
  • Nintex Partner
  • April 17, 2018

With "NWF$('#' + Question1).find("input:checked").val("Yes")" one would set the radio button or checkbox. What you need to use is "if (NWF$('#' + Question1).find("input:checked").val() == "Yes") {}"


Forum|alt.badge.img+11
  • Nintex Partner
  • April 17, 2018

As for the AssessmentVlaue. If this is a choice field as well, then you may have to set the internal option value to checked as well. If AssessmentValue is just a text then your instruction should work just fine.


Forum|alt.badge.img+9
  • Author
  • April 18, 2018

Thank you. AssessmentValue is text field. Are you able to help me further with this JQuery? I can't seem to get it to work in Nintex.

var Questions = [
NWF$('#' + Question1),
NWF$('#' + Question2)
]

$(Questions).each(function(i) {
$(this).click(function() {
if (NWF$('#' + Question1).find("input:checked").val() == "Yes" && NWF$('#' + Question1).find("input:checked").val() == "Yes" ) {
NWF$('#' + AssessmentValue).val('Completed');
}
else {

NWF$('#' + AssessmentValue).val('');
}
})
})


Forum|alt.badge.img+11
  • Nintex Partner
  • April 18, 2018

Are you only checking Question1 for all Questions? The if "ands" the same condition twice (Question1), so I guess the 2nd one should be for Question2 (-> if (NWF$('#' + Question1).find("input:checked").val() == "Yes" && NWF$('#' + Question2).find("input:checked").val() == "Yes" ))

Have you tried $(this).change() in stead of $(this).click()?


Forum|alt.badge.img+9
  • Author
  • April 18, 2018

Yeah I realised it should be Question 2 and not 1.

$(this).change() also didn't work; I have used $(this).click() in an earlier function and it works.


Forum|alt.badge.img+11
  • Nintex Partner
  • April 19, 2018

And what if you replace the jQuery $ with the Nintex jQuery NWF$, so e.g. NWF$(this)?


Forum|alt.badge.img+9
  • Author
  • April 23, 2018

That worked! Thank you!