Javascript to check a checkbox on a button click

  • 13 March 2018
  • 7 replies
  • 25 views

Badge +7

I am trying to programmatically change the value of a Yes/No column from its default of No to Yes when the user clicks a button. I am missing one piece and I'm not sure what. Appreciate any advice.

Checkbox - name is ApprovalbyDonor.

In Advanced properties | Client ID JavaScript variable name, I have jsApprovalbyDonor

Save button - In Advanced | Client click, I have ClickMe()

The form's Settings | Custom Javascript, I have
function ClickMe() {
   NWF$('#' + jsApprovalbyDonor).attr('checked',true);
   alert('hi');
}

The javascript is called when I click the save button. The 'hi' alert box does appear (at which time I can see my checkbox on the form has been checked as well). But the underlying list value associated with the checkbox - ApprovalbyDonor does not change from No to Yes on that Save click.

(Right now I have the checkbox visible but once I get this working, its visibility property will be set to false... this is why I'm not having the user just manually check the box).


7 replies

Badge +7

I ended up going a different route. I used this suggestion -   - and went with option 1. It feels a bit cludgey but it's also easy and it works for what I am needing.

Userlevel 2
Badge +11

Hi ‌,

Just one tip: if you need a hidden control on a form to be set from JS, don't hide it using the control's Appearance setting, but in stead use a Formatting rule to hide it. Why? The former will not render the control and as such it would not be available to your JS, while the second will render the control, but not show it in the browser.

Badge +1

@mindymac03 What was the suggestion you went with? It didn't post in your comment. I am having the same issue you were having with the underlying value not changing. 

Badge +7

Good question! Let me figure out which donation form this was and get back to you. Sorry I don't remember off hand.

Badge +7
I am looking at the form in question. It does not have custom javascript any more. What what what was that URL supposed to be above.
Badge +7

@Evosolutions This is the URL: https://community.nintex.com/thread/2712

 

Badge

You can use the following solution.

The easiest one is to use a button control which action is Save and Submit. In the Advanced settings of the button, you can connect it to a number column (which default value is 0) and set its value to 1. Then you can build a workflow that will be conditionally executed at the update of the item if the number column is equal to 1. In this workflow, you can then execute another workflow or directly populate the SharePoint list. This possibility is explained by Vadim Tabakman in this article: Nintex Forms - Save or Submit - Vadim Tabakman . The inconvenience of this method is that your form has to be saved and closed to start the workflow. While getting the list items, please check null value or empty value of checkboxes. If a checkbox is unchecked, it doesn't get sent, so setting it's value to 0 if it isn't checked isn't going to help - it will always return NULL. There are two ways to fix this easily: 1) Assume a NULL in the PHP params means the checkbox is unchecked.

Reply