PDA

View Full Version : Need help with radio buttons



britain
Aug 14th, 2007, 08:00 PM
hello i am making a text based mafia game and while checking the html code for my page i found there is something wrong with my script instead of letting the me only select one radio button it lets me select them all :confused:

here is my code for it

<html>
<head>
<title>The Dark Side Of Britain</title>
</head>
<body bgcolor="#000000" text="#B8860B">
<center>
<table width="25%" border="3" bordercolor="#FF0000">
<tr>
<td><img src=""</td>
</tr>
<tr>
<td align="middle"><b>Crimes</b></td>
</tr>
<tr>
<td><form><input type="radio" name="crime" value="rob">rob a child</form></td>
</tr>
<tr>
<td><form><input type="radio" name="crime" value="rob a shop">rob a shop</form></td>
</tr>
<tr>
<td><form><input type="radio" name="crime" value="rob a supermarket">rob a supermarket</form></td>
</tr>
<tr>
<td><form><input type="radio" name="crime" value="rob a computer store">rob a computer store</form></td>
</tr>
<tr>
<td><form><input type="radio" name="crime" value="rob a house">rob a house</form></td>
</tr>
<tr>
<td><form><input type="radio" name="crime" value="rob a rich man's house">rob a rich mans house</form></td>

</table>
</body>
</html>


what do i have to add/change to only select one

thanks in advance

mcjwb
Aug 14th, 2007, 09:18 PM
All your radio buttons need to be in the same form, you have put each radio button in its own form.
Put the form tags outside the table.

britain
Aug 14th, 2007, 09:39 PM
i hav done wat you said but m afraid its still not doin

<html>
<head>
<title>The Dark Side Of Britain</title>
</head>
<body bgcolor="#000000" text="#B8860B">
<center>
<form>
<table width="25%" border="3" bordercolor="#FF0000">
<tr>
<td><img src=""</td>
</tr>
<tr>
<td align="middle"><b>Crimes</b></td>
</tr>
<tr>
<td><input type="radio" name="crime1" value="rob">rob a child</td>
</tr>
<tr>
<td><input type="radio" name="crime2" value="rob a shop">rob a shop</td>
</tr>
<tr>
<td><input type="radio" name="crime3" value="rob a supermarket">rob a supermarket</td>
</tr>
<tr>
<td><input type="radio" name="crime4" value="rob a computer store">rob a computer store</td>
</tr>
<tr>
<td><input type="radio" name="crime5" value="rob a house">rob a house</td>
</tr>
<tr>
<td><input type="radio" name="crime6" value="rob a rich man's house">rob a rich mans house</td>
</tr>
<tr>
<td><input type="button" name="commitcrime" value="commit crime"></td>
</tr>
</table>
</form>
</body>
</html>

mcjwb
Aug 14th, 2007, 09:45 PM
That's because you have also changed the name of each radio button.
A group of radio buttons have to all have the same name.

britain
Aug 14th, 2007, 09:50 PM
yeh thank you mcjwb for all your help :)

mcjwb
Aug 14th, 2007, 09:51 PM
no problem.