The user has the option [Approve] [Reject] at the approval stage.
It is a choice radio option and I like to update the Comment box to say I have Approved this request when the choice [Approve] has been ticked.

I have looked around and trying to put something together, but I am having not much luck.

var selectedValue = NWF$('#' + ddlContentType).find("input:checked").siblings("label").text() == "Approve";
NWF$("#"+txtAppendix).val("I have Approved this request");

JavaScript variable names:
ddlContentType is the Choice with the Approve or Reject option.
txtAppendix is the Comment box where I like it to update.

The above script, updates the CommentBox, a soon as an option is selected. The idea behind is to update the CommentBox only when Approve option is selected otherwise it needs to remain blank.

Any advise?
I am a neewbie at scripting..


You're very close, you're just not actually checking to see IF the selected value is approved or not, and only then take action. Since you never actually check IF the condition you want is there, then the line of code that adds the statement to the text box always executes.

This line here

var selectedValue = NWF$('#' + ddlContentType).find("input:checked").siblings("label").text() == "Approve";

is a little misleading because the variable name is selectedValue, which sounds like it should be equal to either "Approve" or "Reject" (i.e. the selected value), and it would be if the line ended at .text(). But since you added == 'Approve' at the end, then really selectedValue is going to be true or false.

You could work with that, and just check

if (selectedValue === true) {
    // if it's true, it means the selected option label equals "Approve", as per that line above

but I'm not a fan of misleading variable names, so I would recommend restructuring a little bit to make it more clear what you are actually checking:

NWF$(document).ready(function () {
    NWF$("#" + ddlContentType).change(function () {
        // get the text value of the label of the selected option
        var selectedValue = NWF$('#' + ddlContentType).find("input:checked").siblings("label").text();

        // check to see if that does equal "Approve"
        if (selectedValue === "Approve") {

            // if it does, add your statement to the text box
            NWF$("#" + txtAppendix).val("I have Approved this request");

        } else {

            // if it does NOT, then clear the text box,
            // in case someone accidentally clicked on "Approve" and
            // added the statement, but then changed their mind
            NWF$("#" + txtAppendix).val("");

  • I couldn't have done it better :) thank you for your advise and support. – Bucki Feb 19 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.