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

Question

Question

Value of Radio Button Not Populating to Next Form

asked on June 13, 2017

I have a field that will either set the radio button to Not Required or Complete depending on whether or not there was a person assigned to the QAE role.

$(document).ready(function(){

//Set value for QAE Review radio button
  if (($('.qae input').val() == "") || ($('.qae input').val() == "N/A"))
  {
  $('#Field192-0').attr('checked', false); //QAE is Not Required
  $('#Field192-1').attr('checked', true);
  $("#Field192-0").prop("disabled", true);
  $("#Field192-1").prop("disabled", true);
  }
  else
  {
  $('#Field192-0').attr('checked', true); //QAE is Complete
  $('#Field192-1').attr('checked', false);
  $("#Field192-0").prop("disabled", true);
  $("#Field192-1").prop("disabled", true);
  }

});  //close document.ready

It works great for the first form, however, the value is not set for the next form.

I do not have any javascript in the second form that would cause this to change. How can I get the radio button to populate to the next form?

0 0

Answer

SELECTED ANSWER
replied on June 13, 2017 Show version history

Hi Gloria,

I think the problem is that you are setting the fields to "disabled." I ran a quick test and even if I disabled the field after populating the value, Forms still ignored the input when it moved onto the next Form in the process.

This could be a bit tricky to solve because it looks like "read-only" for radio buttons is just disabled, and from I can tell, Forms doesn't seem to ever store new values/inputs for disabled fields.

The only way I can think of right now to get around this would be to add another .click event to the Submit button so it re-enables the fields right before submitting the form.

$(document).ready(function(){  
  $('#YourField input').change(function(){
    setReadOnly($('#YourRadio-0'),false);
    setReadOnly($('#YourRadio-1'),false);
    
    // Make your selection here
    $('#YourRadio').click();
    
    //setReadOnly($('#q3 input'),true);
    setReadOnly($('#YourRadio-0'),true);
    setReadOnly($('#YourRadio-1'),true);
  });
  
  // This should re-enable them right before submission so the values are captured
  $('input.Submit').click(
    function(){
        setReadOnly($('#YourRadio-0'),false);
    	setReadOnly($('#YourRadio-1'),false);
    }
  );
});

function setReadOnly(e,x){
    if(x){
        // Set radio input to 'read-only'
        e.attr({'disabled': 'true', 'backend-disabled': 'True'});
    } else {
        // Remove readonly from radio input
        e.removeAttr('disabled backend-disabled');
    }
}

EDIT: I mistakenly put input[type=radio] in that first jquery selector when it should just be input.

0 0
replied on June 20, 2017

Thanks! I used your idea and turned off the disable once the Approve button is clicked. Worked great!

$(document).ready(function(){

//Set value for QAE Review radio button
  if (($('.qae input').val() == "") || ($('.qae input').val() == "N/A"))
  {
  $('#Field192-0').attr('checked', false); //QAE is Not Required
  $('#Field192-1').attr('checked', true);
  $("#Field192-0").prop("disabled", true); //Disable so it cannot be changed
  $("#Field192-1").prop("disabled", true); //Disable so it cannot be changed
  }
  else
  {
  $('#Field192-0').attr('checked', true); //QAE is Complete
  $('#Field192-1').attr('checked', false);
  $("#Field192-0").prop("disabled", true); //Disable so it cannot be changed
  $("#Field192-1").prop("disabled", true); //Disable so it cannot be changed
  }

//capture timestamp
  $('.Approve').click(timestamp);
 
  function timestamp() {
    
    if ($(this).hasClass('Approve')) {
       $("#Field192-0").prop("disabled", false);
       $("#Field192-1").prop("disabled", false);
    }
  };

});  //close document.ready

 

0 0

Replies

replied on July 1, 2024

Hello, 

Does some one happen to know how can I convert the following code to modern form JavaScript?

"$('#q130 div input:radio').attr('disabled','disabled');"

 

Thank you for helping.

 

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

Sign in to reply to this post.