cancel
Showing results for 
Search instead for 
Did you mean: 
cjones69
Nintex Newbie

Javascript to set a checkbox to true by button click

Jump to solution

I need to create a button that will set a hidden checkbox field to true and then submit the form. I'm not a coder, but dally with javascript occasionally. I've searched everywhere for pre-existing code to do the task I am attempting, but can't find anything. I saw some posts about UNchecking radio buttons using javascript and I tried to modify it to make it work with the checkbox, but no go. Below is the code I tried:

NWF$('document').ready(function(){var strBeginReviewValue = NWF$('#'varBeginReviewID).find("input:checkbox:not(:checked)").val();NWF$('#'varBeginReviewID).find('input[value='\'strBeginReviewValue'\']').attr('checked', true);});

varBeginReviewID is the javascript ID for my checkbox. I placed this code in the client click field of the button. It does not set the checkbox to checked. The code above also does not submit the form. If anyone can help me get the button to do both the checking of the checkbox and submitting the form, it would be greatly appreciated!


Thanks!

Chris

Labels: (3)
0 Kudos
Reply
9 Replies
Automation Master
Automation Master

Re: Javascript to set a checkbox to true by button click

Jump to solution

if you want the checkbox always checked, wouldn't it be easier to set its default value to checked?

you wouldn't need any javascript then

0 Kudos
Reply
cjones69
Nintex Newbie

Re: Javascript to set a checkbox to true by button click

Jump to solution

Hi Marian,

No, the use case is this:

The "Begin Review" checkbox is a trigger to start a review process workflow. Rather than have the user check a box and then click save, I want them to click a button which sets the Begin Review checkbox to true/yes, saves and closes the form and starts the workflow.

For some reason, you can set a button to send a value to single line of text, number and choice fields, but not to a checkbox. Seems like that ought to be a simple thing to do, so not sure why Nintex didn't include it as a field type to which you can send a value (true/false, 0/1, yes/no).

I have tried on a demo list and was able to make this work by changing Begin Review to a single line of text and using "Yes/No" as the values in the field. However, the list in production is in use and I don't want to have to change column types, so JavaScript to set the checkbox on button click is my best option. I was previously using InfoPath, so had no issues doing this at all. I have to upgrade all InfoPath solutions to Nintex Forms.

0 Kudos
Reply
Automation Master
Automation Master

Re: Javascript to set a checkbox to true by button click

Jump to solution

but that still sounds to me that you want/need to have it checked for each and every (new) item submitted, don't you?

since it is hidden, user doesn't have a control over it. and it shouldn't matter whether you set it checked from default value or from javascript. setting it from default value is much easier to implement and especially easier to maintain later on (nintex use to change controls' models almost with every release, so you have to be careful with upgrades and proof check all your custom js functionality).

or is there any further logic that I miss which controls when it should be checked and when not?

0 Kudos
Reply
cjones69
Nintex Newbie

Re: Javascript to set a checkbox to true by button click

Jump to solution

Hi Marian,

Thanks for your comments. The current order of operation is:

Standard User submits a form with information to the list. (Begin Review cannot be checked at this point)

Admin team receives notification that a submission has been received.

Admin team can look at submission without beginning review process. (Begin Review should not be checked at this point)

Admin team either checks the checkbox and saves the form to begin the review process or clicks a button to begin review process (latter is best option and either way, Begin Review should now be checked).

After Review process is begun, Review Team receives notification to review submission.

So the checkbox cannot be checked at all times as it is the trigger to begin the review process workflow.

0 Kudos
Reply
Automation Master
Automation Master

Re: Javascript to set a checkbox to true by button click

Jump to solution

that sounds to me to be already part of approval workflow then something that should checked in form.

but if you insist on checkbox approach try following

NWF$('#'+jsvarCheckBox).click();
0 Kudos
Reply
cjones69
Nintex Newbie

Re: Javascript to set a checkbox to true by button click

Jump to solution

Thanks. I will try this. I made a mistake in my previous comment. The checkbox is not the trigger to start a workflow, but a trigger to change state in the workflow state machine. The workflow starts on document upload.

0 Kudos
Reply
cjones69
Nintex Newbie

Re: Javascript to set a checkbox to true by button click

Jump to solution

I was not able to get this solution working as intended. I had to change the checkbox to a choice column with Yes or No as options. Then setting the button to change the Begin Review column to Yes was simple out of the box functionality.

0 Kudos
Reply
Automation Master
Automation Master

Re: Javascript to set a checkbox to true by button click

Jump to solution

how did you hide the checkbox? by its appearance settings?

place the checkbox into a panel and configure a formatting rule to hide the panel.

0 Kudos
Reply
Highlighted
cjones69
Nintex Newbie

Re: Javascript to set a checkbox to true by button click

Jump to solution

Ah, now I get it. I didn't have the checkbox on the form. I was trying to set the value for the checkbox to Yes in the list. Your solution works with the checkbox on the form.

Thanks!

Reply