Skip to content
Advertisement

Radio not disabling due to loop

This is my radio disabling function.

<script>
function disableElement()
{
var dis = '<?php echo $dis_value; ?>';
document.getElementById(dis).disabled=true;
}
</script>

And I will call it when the page is loaded!

<body onLoad="disableElement()">

And the radio button is displayed through loop..!

echo '<form method="post" action="trainingserver.php">';
$i = 1;
while($i <= $num_rows)
{
echo '<input type="radio" id="dis"'.$i.'"" name="select" value="'.$i.'" />';
echo  $poke[$i]."<br>";
echo 'Level:'.$level[$i]."<br>";
echo 'Health:'.$health[$i]."<br>";
$i++;
}
echo '<input type="submit" name="submit" value="Select Pokemon!" />';
echo '</form>';

So the radio ids would be like: dis1,dis2 … dis6

But its not disabling it…! I think its because of the while loop, I used..! what should I do..?

Advertisement

Answer

this line:

echo '<input type="radio" id="dis"'.$i.'"" name="select" value="'.$i.'" />';

should be (note the removed quotes from id):

echo '<input type="radio" id="dis'.$i.'" name="select" value="'.$i.'" />';
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement