Disable Radio after First Selection

By: Daveed Flexer | Asked: 07/27/2023
ForumsCategory: How-toDisable Radio after First Selection
Daveed Flexer asked 1 year ago

I tried various Javascript and Jquery solutions but they don't seem work, or cause errors.

The goal is to not allow the user to change their answer after they select. Has anyone been successful with this?

Form is a step by step Quiz with radio as buttons.

Some attempts that seem to work but then break;

https://stackoverflow.com/questions/48082982/how-do-i-disable-all-radio-buttons-after-select Break the Next Button

 

Jquery  (function($) {
$(':radio').change(function(){
$(':radio').not(this).prop("disabled", true);
});
})( jQuery ); Causes error on "start again" Thanks  

1 Answers
Victor Font answered 1 year ago
You're not using a proper selector. Use this: $('input[name="item_meta[XXX]"').prop("disabled", true). Change XXX to the ID of the radio field.
Daveed Flexer replied 1 year ago

Thank you Victor, but I was looking for a generalized solution as this needs to be applied to all the quiz questions. Additionally this form will be duplicated and reused by the client many times over, so it has to be a generalized solution. I will try some sort of loop to target the ID's, but need to find a way to make it duplicatable without it failing.

Daveed Flexer replied 1 year ago

I need to work on this more, as even a specific ID causes the "next" button to fail, and refresh the same question, with an error that it is blank. Console does not show a JS error, so will need further exploration.

IMO this should be a built in functionality for Quiz. I will add this as a Feature Request, but it probably won't help me for this project.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right