cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Set a field value from a button

Jump to solution

Good day everyone,

I have a field that I want to set the value on when a button is clicked, I know this needs to be done with JS, but I am not sure how to go about it.  So for example when Button1 is clicked field1 = 1, when Button2 is clicked field 2 = 2...etc.

Thanks,
Jennifer

0 Kudos
Reply
6 Replies
Workflow Hero

Re: Set a field value from a button

Jump to solution

Hi there Jennifer Wiskemann‌!

Let's say the field name is "txtColour" and button 1 is "blue" and button 2 is "red". 

In your Settings > Custom JS, you'll want to paste something like:

function SetColourBlue() {
NWF$ ( '#' + txtColour ).val( 'Blue').trigger('change');
 }

function SetColourRed() {
NWF$ ( '#' + txtColour ).val( 'red').trigger('change');
 }

Then within your button for Client Click you can put SetColourBlue(); on button 1 and SetColourRed(); on button 2.

There is probably an easier way to go about this, but this is the first thing that comes to mind for me.

Cheers!

Rhia

Reply
Workflow Hero

Re: Set a field value from a button

Jump to solution

I actually found a way to do it without code.  If you select the button and open the settings there is an option under advanced to set the return value.

Thanks for all the great suggestions!
Jennifer

Reply
Workflow Hero

Re: Set a field value from a button

Jump to solution

For the next people:

Don't forget to connect your button to the decision control if you wanna transfer the value.

And to know the correct value, press F12 on the decision form when simulating and click on the object in the DOM explorer, value will be in the code for the selected object.Checkbox value

Reply
Workflow Hero

Re: Set a field value from a button

Jump to solution

How to do this in the responsive forms?

0 Kudos
Reply
Workflow Hero

Re: Set a field value from a button

Jump to solution

Hi Debo Chakraborty‌ -- CSS & Javascript are not supported in Responsive Forms so you will be unable to do this. You will need to create a classic form to take advantage of these snippets of code.

0 Kudos
Reply
Workflow Hero

Re: Set a field value from a button

Jump to solution

Laurent Angevelle Rhia Wieclawek Jennifer Wiskemann   

Is there a way to do this using the return value (without javascript) so that the form does not save every time someone pushes the button to pass the value? I only want the form to save when the user clicks a button called Save. I got the button called Dispute to push the dispute value to the TicketTrouble_Rating field but it saves every time the button is pushed. now I'm trying to work out what to putin the workflow to keep it from firing every time the button is pushed due to a status field int he background auto firing once the item is updated.

Also, anyone have any ideas why every time I add ANY javascript to my  forms they do not work in my browser IE11? CSS works in chrome but not IE11.I

IE 11

SharePoint 2016 On Prem

Nintex 2016   Classic -

Due to flexibility I wanted to use the JavaScript for this passing values scenario but it nothing happens in form when I use JavaScript so I used the value returned option. Seems to be only thing to work.

I was thinking it was a local setting in browser but I am unable to figure out why JavaScript from the form will not work. I added url to compatibility settings, removed them, deleted temp/cached files, checked to see if anything was getting blocked in intranet or trusted sites for JavaScript. I must be missing something. I have verified the exact scripts work for many others on here and I can't get seem ANY of the ones I attempt to work. So either I am doing something wrong in the scripts or there is something going on with my local system /browser settings.

No errors, just nothing happens when editing form.

Attempting to hide or disable a value within a field I don't want users to submit.Due to JavaScript not working I am now using the method of disabling the field with a rule and then using a button to set the field value. This works using the pass a value but I need it to be more flexible and would prefer if JavaScript was working.

NOT WORKING

Control Settings-

Form Settings - 

....Custom CSS works but not in IE 11 (only chrome) had to resort to rules and trying javascript but javascript not working in IE or Chrome it looks like.

???

Thanks,

L

0 Kudos
Reply