facarroll Posted November 23, 2010 Share Posted November 23, 2010 I have multiple radio buttons staying selected on a several forms in different scripts when they were working properly (only one selects at a time) yesterday. The scripts have not been altered. None of my scripts containing radio buttons are working as they should. I can select all of the buttons at once. Does anyone have a clue about what could be going on? Quote Link to comment Share on other sites More sharing options...
revraz Posted November 23, 2010 Share Posted November 23, 2010 Our magic code seeing 8 ball is broken at this time, so I'm afraid you'll have to post some code. Quote Link to comment Share on other sites More sharing options...
facarroll Posted November 23, 2010 Author Share Posted November 23, 2010 Fair enough. <form method="post" enctype="multipart/form-data" action="<?PHP echo $_SERVER["PHP_SELF"]; ?>"> <tr> <input type="text" name="given" value="" /><br />Enter the Given Name <p> <input type="text" name="family" value="" /><br />Enter the Family Name <p> <input type="text" name="transferCode" value="" /><br />Enter the Transfer Code <p> <input type="text" name="userCode" value="" /><br />Enter the User Password <p> <input type="radio" name="userGroup_1" value="<?php echo $group1; ?>" /><?php echo $group1; ?> <p> <input type="radio" name="userGroup_2" value="<?php echo $group2; ?>" /><?php echo $group2; ?> <p> <input type="radio" name="userGroup_3" value="<?php echo $group3; ?>" /><?php echo $group3; ?> <p> <input type="radio" name="userGroup_4" value="<?php echo $group4; ?>" /><?php echo $group4; ?> <p> <input type="radio" name="userGroup_5" value="<?php echo $group5; ?>" /><?php echo $group5; ?> <p> <input type="radio" name="userGroup_6" value="<?php echo $group6; ?>" /><?php echo $group6; ?> <p> Select the Allocated Student Group <p> <input type="submit" value="submit" name="Send Data"> </form> Quote Link to comment Share on other sites More sharing options...
facarroll Posted November 23, 2010 Author Share Posted November 23, 2010 I've figured out that the name field must be identical in each case, but accompanied by an id field like this. <input type="radio" name="userGroup" id="1" value="<?php echo $group1; ?>" /> <input type="radio" name="userGroup" id="2" value="<?php echo $group1; ?>" /> <input type="radio" name="userGroup" id="3" value="<?php echo $group1; ?>" /> But can anyone tell me how the POST process should work in this case? Quote Link to comment Share on other sites More sharing options...
dadamssg Posted November 23, 2010 Share Posted November 23, 2010 shouldn't all the names of the radio buttons be the same? <input type="radio" name="userGroup" value="<?php echo $group1; ?>" /><?php echo $group1; ?> <input type="radio" name="userGroup" value="<?php echo $group2; ?>" /><?php echo $group2; ?> <input type="radio" name="userGroup" value="<?php echo $group3; ?>" /><?php echo $group3; ?> ..and so forth Quote Link to comment Share on other sites More sharing options...
dadamssg Posted November 23, 2010 Share Posted November 23, 2010 to get the value in the php script it would be $_POST['userGroup']. And depending on which button they selected you would get whatever $group1, $group2, $group3, $group4, $group5, or $group6 is. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 23, 2010 Share Posted November 23, 2010 dadamssg is correct. To create a group of radio buttons, you'd give them all the same name attribute. They would then each have different value attributes, and only the value from the one that is selected would be in the $_POST array. <!-- group 1 --> On: <input type="radio" name="first" value="on"><br> Off: <input type="radio" name="first" value="off"><br> <br> <!-- group 2 --> Green: <input type="radio" name="second" value="green"><br> Blue: <input type="radio" name="second" value="blue"><br> Yellow: <input type="radio" name="second" value="yellow"><br> Quote Link to comment Share on other sites More sharing options...
hennzo Posted December 3, 2010 Share Posted December 3, 2010 Hi, I am new in this forum. I saw your question, and I registered just to answer it. Instead of write this code: <input type="radio" name="userGroup" id="1" value="<?php echo $group1; ?>" /> <input type="radio" name="userGroup" id="2" value="<?php echo $group1; ?>" /> <input type="radio" name="userGroup" id="3" value="<?php echo $group1; ?>" /> Write like this : <?php switch($_POST['userGroup']){ case '1': $group1= 'checked'; break; case '2': $group2= 'checked'; break; default: $group3= 'checked'; } ?> <input type="radio" name="userGroup" id="1" value="1" <?php echo $group1; ?> /> <input type="radio" name="userGroup" id="2" value="2" <?php echo $group2; ?> /> <input type="radio" name="userGroup" id="3" value="3" <?php echo $group3; ?> /> Which means that group3 is checked by default. If you don't want any default checked, just put it in the case option like others. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.