Value of Multiple Radio Buttons Within a Conditional Statement


Badge +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

Userlevel 2
Badge +11

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

Userlevel 4
Badge +11

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..

Badge +9

Yes they are.

Badge +9

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');
}
})

Userlevel 2
Badge +11

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") {}"

Userlevel 2
Badge +11

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.

Badge +9

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('');
}
})
})

Userlevel 2
Badge +11

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()?

Badge +9

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.

Userlevel 2
Badge +11

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

Badge +9

That worked! Thank you!

Reply