dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: Getting values from radio buttons named dynamically

  1. #1
    Join Date
    Aug 2012
    Posts
    2

    Getting values from radio buttons named dynamically

    I have "n" number of rows being returned by a sql statement. Works great. For every row returned, I would like the user to pick an option (either option 'a' or option 'b')

    As standard practice a while loop is used to iterate through each row, and I attempt to name my options by the row number. However, I run into problems when I attempt to get the value of the radio button the user has selected.

    I can't seem to dynamically get the value of the radio button named 1 in the first loop (or any loop with it's appropriate name) of the where clause. Or in other words: I'm looking to see why 'choice' is not getting the value selected by the user in

    Code snippet here:

    $counter = 1;

    while($row = mysql_fetch_array($result))
    {

    echo "<form action='updatepics.php' method='post'>";
    echo "<input type='radio' name='m" . $counter . "' value= ". $row['f_id'] ."> " . $row['Favorite'];
    echo "<input type='hidden' name='game' value=" . $counter . ">";
    echo " vs " . $row['Underdog'] ." ";
    echo "<input type='radio' name='m" . $counter . "' value= ". $row['d_id'] ."> ";

    echo "<br>";
    echo "<input type='hidden' name='choice' value=" . $_GET["m" . $counter] . " >";
    echo "<input type='submit' value='Make Choice'>";
    echo "</form>";
    $counter ++;
    }



    updatepics.php:

    Game
    <?php
    echo $_POST['game'];
    echo " " . $_POST['player'] . " picks: ";
    echo " " . $_POST['choice'] ;
    ?>

    output of updatepics.php...
    Game 1 granny picks:

    Notice 'choice' is null

  2. #2
    Join Date
    Aug 2012
    Posts
    2
    Wow, I can't believe you should wait this long to have the moderator review the question before posting. With such a long lag-time, I was able to work through different approaches to get this to work.

    I dumped the idea of dynamically radio buttons, and just went with static names. It worked.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles