You are viewing limited content. For full access, please sign in.

Question

Question

populate radio button in a table from an external radio button

asked on October 27, 2022

I have a radio button.

I need to populate the Action button in the table below based on the above field if it is not empty. If it is empty, the user will select the appropriate action.

Note that the items are not in the same order as the previous field. The "Send for Revision" choice should be selected if the "Send back for revision" choice is selected in the first field (#q191) and the "Reject" choice should be selected for the "Cancel" option.

I have tried to solve this from various posts in forms, but I am still learning to code and keep running into road blocks.

The code I thought was going to work, I found here...

https://answers.laserfiche.com/questions/47617/How-can-I-populate-a-field-in-forms-automatically-when-a-user-makes-a-radio-button-checkbox-or-dropdown-selection#47807

Here is my code, but I think I have to refernce the radio buttons in a different manner. Is this correct and can you help?

Also, this form does loop, so I will clear #q191 with each loop. Will my value still hold in the table?

0 0

Replies

replied on October 27, 2022

The other post might be overcomplicating things for your scenario. 

  $('.sourceRadio input').on('change',function(){
    // get value associated with selection
    var selection = $(this).val() == 'Cancel' ? 'Reject' : 'Send_for_Revision';
    
    // select radio option with same value as source selection
    $('.targetRadio input[value=' + selection + ']').prop('checked',true).change();
  });

Note the "value" has to match the underlying value of the option, not the display text.

 

Or, if you would rather use indexes instead of value comparison

  $('.sourceRadio input').on('change',function(){
    // get index value based on selection
    var index = $(this).val() == 'Cancel' ? 3 : 1;
    
    // select radio option with target index
    // the .choice part is there because radio fields have hidden inputs
    $('.targetRadio .choice input').eq(index).prop('checked',true).change();
  });

Just map the indexes accordingly (i.e., 1 for the 2nd option, 3 for the 4th option).

1 0
replied on December 13, 2022

I've tried both codes, but I can't seem to get it to work. I put sourceRadio and targetRadio in the CSS Class for each field. Was I supposed to change anything else? Doesn't the targetRadio button need to be referenced differently because it is in a table?

0 0
replied on December 13, 2022

Are you getting any javascript errors in the browser console?

Try adding some stuff like console.log('test 1'); in different parts of the code that way you can see if it is running at all, and if it is breaking at any particular point.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.