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

Question

Question

Set radio button value based on a field

asked on January 5, 2017

I know I am so close to a solution but just need a push in the right direction!

 

So I have a field that fills itself out based on a lookup done earlier, one of its possible values is SENR. Class = levelhid

Then I have some radio buttons that I would like to fill out based on the levelhid. Class = level

The expected result if the levelhid = SENR would be for the level to check "Senior" radio button.
 

$(".levelhid").change(function(){
    var levelhid = $(".levelhid input").val();

    if (levelhid == "SENR"){
      $(".level input:check").val("Senior");
      }
    else if (levelhid == "ADJ"){
      $(".level input:check").val("Adjunct");
      }
    else if (levelhid == "MSTR"){
      $(".level input:check").val("Master");
      }
  });

Thanks!

0 0

Replies

replied on January 6, 2017

Lidija,

I was able to use the code below to accomplish this task.  Note that I am not using an IF statement to determine the value, rather, taking the value in the lookup and matching it with my radio field.  

$(document).ready(function () {
var radioValue = $('q1 input').val();//This is the value of your lookup field, likely some text, string, etc.
$('q2').find($('input[value="' + radioValue + '"]')).attr('checked', true);//q2 is the radio button
});

Your code would look something like:

$(document).ready(function () {
$(".levelhid").change(function(){
    var levelhid = $(".levelhid input").val();
$('.level').find($('input[value="' + levelhid + '"]')).attr('checked', true);
     });
  });

Note: you will want to make sure that your radio values match the case of what your lookup will return.

Hope that helps.

Nate 

2 0
replied on January 9, 2017 Show version history

Thanks Nate, I tried it and it didn't work so I will play around with it but I am sure that the code you wrote is great! I will probably create a fresh form to test this code in, my actual form's Javascript code is quite long and fragile.

0 0
replied on July 2, 2020

Nate, I'm doing something similar, where I'm filling hidden fields with a lookup, then I want to set radio button values based on that.  The main difference is that these text and radio fields are all in a table.  Could this code be used in that manner?  Would it also require using CSS?  Please note that I have very little experience with Javascript/CSS, so I need clear instructions on implementing the code.

Thanks ahead of time for your assistance!

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

Sign in to reply to this post.