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

Discussion

Discussion

Make multiple fields read-only with Javascript based on Radio Button choice

posted on March 5, 2019

I am trying to make certain fields set to read-only for an approval step based on a radio button choice.  The first date field gets set read-only just fine but all fields after are not being set.  

Here is my current code:

$(document).ready(function () {
    WhoStart();  
});

function WhoStart()
{
  var StartValue = $(".RadioBtn input:checked").val();
   
  if(StartValue == 'Super'){
  	$('.Date input').attr('readonly', true);
    $('.DropDown input').attr('readonly', true);
    $('.RadioBtn2 input').attr('readonly', true);
  }
}

There are only two options for the Radio Button 1.  'Super', 'Not Super'

 

The idea is these fields are hidden the first time the document loads.  I would make the choice radio button read-only as well so the form could not go back to open fields.

0 0
replied on March 5, 2019

I should mention the DropDown field is being populated by a database lookup.  The data should already exist in the field, but the lookup may be prioritizing over the read-only setting.

0 0
replied on March 6, 2019

if .DropDown is an actual drop down list, you should use select instead of input. Not sure what is wrong with .RadioBtn2 as radio buttons are normally inputs. Does it give an error under the F12 tools?

0 0
replied on March 6, 2019

Yes,

0:158 Uncaught TypeError: Cannot set property 'readOnly' of null

See's the second radio button, since there is no default option selected, as NULL.

I happened to use that Radio Button in this test as an addition.  I moved from using that button to another field for testing.

Thanks for pointing that out!

It looks like the ReadOnly is only making the Image look ReadOnly:

The boarders are removed.  But then when I click on them, I still have full control over the fields and options within.  Even the Upload button works and I can use it to load more files.

 

0 0
replied on March 6, 2019

I believe I may have found the issue.  With the HTML side those field types can only be 'disabled' not set to read-only.  But in that condition their value would not be send with the form data.

Does anyone know of any options around using 'disabled'?

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

Sign in to reply to this post.