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

Question

Question

Disable radio button on a form using java script

asked on April 12, 2022

I have a form where i have to disable a radio button (Request another course) when the Course Count field  returns a 1. 

Other possible return values for this course count field is blank and 2 and for these values the request another course radio button field should show.

0 0

Replies

replied on April 12, 2022

Hi Rekha, any reason you cannot just apply a field rule to hide the field when Course Count Allowed = 1?

0 0
replied on April 12, 2022

Yes, i already use field rules for the form. And i already use a field rule on that specific field . So when i try to hide it , it says there are conflicting conditions on the same field.

So decided to go with the js option for hiding or disabling the field.

Hope that explains why am trying to use js option here.

0 0
replied on April 13, 2022 Show version history

Try this:
 

$(document).ready(function(){

$("#q1 input").change(function(){

hideRadio();

});

});

function hideRadio(){

if ($('#q1 input').val() == "1"){
  $('#q2 input').prop('disabled', true);
 removeReq()
}

else { 
   $('#q2 input').prop('disabled', false); 
  removeReq();
  addReq();
}

}


function addReq() {
     removeReq();
     $('#q2 input').attr('required', 'True');
     $('#q2 .cf-label').append('<span class="cf-required">*</span>');
}

function removeReq() {
	 $('#q2 input').removeClass('required').removeAttr('required');
     $('#q2 input').removeClass('parsley-error');
     $('#q2 span.cf-required').remove();
     $('#parsley-id-133').hide();

}

q1 is the single line and q2 is the radio button.

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

Sign in to reply to this post.