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

Question

Question

Make a section read only using a radio button

asked on October 23, 2019

I've seen a few answers to this, but all of them assume that I know how to write JavaScript and/or CSS, which I do not.  I need a step-by-step on how to use a radio button to set a section as read only using JavaScript.  My radio button is element q19 and just has a "Yes" and "No" option.  My section is q30 and has 3 fields in it, 2 text and one drop-down.

Any help on this would be appreciated.

0 0

Answer

SELECTED ANSWER
replied on October 24, 2019 Show version history

Hi Paul, below is the JS code to accomplish what you want. You should be able to copy this directly into the JS window. I assumed you would want the Section to be read only at form load, and they could use the radio button to make it readable or set it back to read only.

This can be made a little more readable if you use CSS by adding a class to the radio field "ie:radio" and the Section to "SectRO" and then change those values in the code

#q30 would become .SectRO and #q19 would become .radio

Hope this gets you where you need to be

Steve

 

$(document).ready(function() {

//this sets the section to read only at form load  
  $('#q30 input').attr('readonly', true);
  
//this runs when the radio button is selected
  $('#q19 input').change(function(){
  
    if ($('#q19 input:checked').val() == "No")

//if the radio value is no, set field to read only
    {
    $('#q30 input').attr('readonly', true);
    }

    else 
//if the radio value selected was not no, set the section to be read 
      
      $('#q30 input').attr('readonly', false); 
   
  }); 
});

1 0
replied on October 29, 2019

That's awesome.  Thanks Steve!

1 0

Replies

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

Sign in to reply to this post.