Update a Radio Button based on previous responses

By: Yoni Sudwerts | Asked: 08/10/2022
ForumsCategory: How-toUpdate a Radio Button based on previous responses
Yoni Sudwerts asked 2 years ago
I have about 10 Yes/No Questions

At the end I have a Radio Button, that I want the results of it to show based on the user's response to the Previous Yes/No Questions (if a person gave certain responses, then the last radio button will show yes, otherwise it will show No)

How can I do this?  
Walter JonesWalter Jones replied 2 years ago

Why are you using a radio button at the end? How are the questions set up? Radio, Checkbox? How are the questions calculated? In other words, if they answer 6 questions as Yes, does Yes appear? What is the logic?

I ask these questions because A WAY TO DO THIS (NOT THE WAY) is you could assign a numerical value to the Yes/No responses of your radio or checkboxes if that is how you are formulating the questions and then add a hidden field that totals that numerical value. Which you could then use to conditionally show Yes Or No because on the total of the answers to the questions.

Bobby Clapp replied 2 years ago

var x = something here to set the value of your Yes/No
var y = something here to set the value of your Yes/No option 2.... and so on

if(X = "Yes") {
jQuery("#field_key").prop("checked", true);
}else if (X == "Yes" && Y == "No"){
jQuery("#field_key").prop("checked", true);
} else {
jQuery("#field_key").prop("checked", false);
}... and so on

#field_key above represents the CSS ID of the final radio button.

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