How to disable other opitons when one option is selected of "radio buttons"?

I am trying to disable other options immediately once an option is selected but using java-script I could not do this. Please help me. I have tried so far

<?php 
	$answer = $exm->getAnswer($number);
			
	if ($answer) {
		while ($result = $answer->fetch_assoc()) {
?>
			<tr>
				<td>
				 <input id="question_radio" type="radio" name="ans" value="<?php echo $result['id']; ?>"/><?php echo $result['ans']; ?>
					
					
				
<script id="question_radio" type="text/javascript">$(":radio").click(function(){
   var radioName = $(this).attr("ans"); //Get radio name
  $(":radio[name='"+radioName+"']:not(:checked)").attr("disabled", true); //Disable all unchecked radios with the same name
});				
					
			</script>
					
					
				</td>
			</tr>
<?php } } ?>
			<tr>
			  <td>
				<input type="submit" name="submit" value="Next Question"/>
				<input type="hidden" name="number" value="<?php echo $number; ?>" />
				  
				</td>
			</tr>

Hi,
I am not an expert. Maybe I don’t understand your question.

I use radio buttons a lot. You can only click one. I suppose the html is made that way

Click one button and it is set. Then if you click another radio button in that set, the previously clicked button is unset. I don’t need php to do that.

Say you have 4 choices: A B C D each choice in that set has the same name, like
name=“rb1” value=“A”>A text for answer A
name=“rb1” value=“B”>B text for answer B
name=“rb1” value=“C”>C text for answer C
name=“rb1” value=“D”>D text for answer D

php has then

$q1 = $_POST[‘rb1’];

Whichever button is clicked, that’s the answer I get!

One thing I found: students are in a hurry, they will often forget a button. So, when you have collected all the variables, run a loop. It sets a value to X if the variable is empty.

None values cause trouble when I am writing the values to an Excel sheet with Python.

for ($i=1; $i <= 22; $i++) {

    if (${"q$i"} == '') ${"q$i"} = 'X'; 
}

Thank you . I will remember and try this.

Sponsor our Newsletter | Privacy Policy | Terms of Service