change field value if field is hidden


Badge +8

Good Day,

I have a set of check boxes [1, 2, 3, 4] that correspond with a set of text boxes [1txt, 2txt, 3txt, 4txt].  I am using the sum function to add the values of the text boxes together and a format rule to display the text box if that corresponding check box is checked.  Example 1 is checked so 1txt appears, if 1 and 2 are checked 1txt and 2txt appear and the values are added. Where I'm running into a problem is that when the check box is unchecked I need to set the value of the text box to 0 so it is not still being added to the total.

Any suggestions would be appreciated, thank you,

Jennifer


4 replies

Userlevel 6
Badge +16

You code to do this on the change event of your checkboxes.

NWF$(document).ready(function(){

NWF$('#'+Check1).change(

function() {

NWF$("#" + textBox1).val('0');

}

);

});

Badge +8

Thank you for the reply! I am new to nintex [obviously] and am not sure where to put the provided code.  I do not see any option for adding JS under the field --> settings area. Could you please point me in the right direction?

Thank you,

Jennifer

Badge +8

Thanks for the reply; it just doesn't seem to want to work, I'm not sure what I'm doing wrong.  I set a variable on the checkbox [valCheckbox] and have the code referencing it in the form:

form.PNG

When you uncheck the box the value of the field should reset to "0".

77710_pastedImage_1.png

Thanks for the help,

Jennifer

Badge +8

That worked! Thank you! One more question for you; it clears the field no matter what checkbox is checked.  I want it to clear box1 only when the first checkbox is checked, box2 when the second box is checked.  Can I do something like this:

NWF$(document).ready(function(){

var checkedValue = NWF$('#' + valCheckbox).val();

          if (checkedValue) = 1

      {

               NWF$('#' + valCheckbox).change(function() {

               NWF$('#' + js1txt).val('0'); }

            elseif (checkedValue) = 2

      {

               NWF$('#' + valCheckbox).change(function() {

               NWF$('#' + js2txt).val('0'); } 

     }

);

});

Thanks again,

Jennifer

Reply