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

Question

Question

JavaScript Code to check a radio button

asked one day ago

I'm as green as one can get with JavaScript, and I'm trying to change that.  I have a Radio button asking the user "Are you a Department Head?" with the options of Yes or No.  I also have a hidden text field that stores a Yes or No value.  Now, I want a radio button selected based off of the value in the hidden text box.  

The checkbox field ID is 8.

The hidden text box field ID is 58.

 

I only have 4 lines of code in JS, and it's not doing anything at all:

LFForm.onLookupDone(function() {
  if(LFForm.getFieldValues){fieldId:58})=="Yes"){
    LFForm.setFieldValues({fieldId:8}, {value: "Yes"});}
}, {lookupRuleId:19});

 

I know that I'm missing something.  I just don't know what it is.

 

0 0

Replies

replied one day ago Show version history

Let's look at your JavaScript:

LFForm.onLookupDone(function() {
  if(LFForm.getFieldValues){fieldId:58})=="Yes"){
    LFForm.setFieldValues({fieldId:8}, {value: "Yes"});}
}, {lookupRuleId:19});

Looks like you have a reversed parathesis there on the 2nd line.

LFForm.onLookupDone(function() {
  if(LFForm.getFieldValues({fieldId:58})=="Yes"){
    LFForm.setFieldValues({fieldId:8}, {value: "Yes"});}
}, {lookupRuleId:19});

That should fix it, but I think we could also set this up another way... 

Rather than bound to a lookup rule, we could set this up to trigger whenever the hidden textbox changes and to set the Radio Button to the value of the hidden text box.

LFForm.onFieldChange(function () {
  LFForm.setFieldValues({fieldId:8}, {value: LFForm.getFieldValues({fieldId:58})})
}, {fieldId:58});
0 0
replied one day ago

That worked!  Thank-you so much!

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

Sign in to reply to this post.