Jump to content

Use of radio buttons in php


stern

Recommended Posts

I am new to php programing with little background in HTML. Most of my knowledge would be in launguages like C++, assembler and raw machine code.
While I am getting better at php data manipulation and DB control (these all make sense) I for the life of me cant get the simple things to work (like radio buttons).
What I want to do is make 4 buttons (can only pick one of the 4) and have the choice return a number (1-4). While I can get the buttons to show and work "visually wise) on the screen, for the life of me I cant get it to give me a value (or I at least cant find "where" I supposed to get it from).

After reading a post on radio buttons on the forum I tried it, but the "create radio buttons with HTML" part has left me in the dark. Here is a code snippet from the part with the radio buttons, and hopefully someone can tell me which really stupid mistake im doing here  lol

            switch($_post["Radiobutton"])
            {
            case "1":
            $val="1";
            break;
            case "2":
            $val="2";
            Bbreak;
            case "3":
            $val="3";
            break;
            case "4":
            $val="4";
            break;
            default:
            $val="0";

            echo "  <div align='left'>";
            echo "    <table width='956' border='0'>";
            echo "      <tr>";
            echo "      #$id ";
            echo "      $question<br><br>";
            echo "      </tr>";
            echo "        <td height='24'>&nbsp;</td>";
            echo "        <td><div align='center'></div></td>";
            echo "        <td><font color='#FFFF80'>A</font>";
            echo "        <input type='radio' name='chk' value='1'> $choice1<br>";
            echo "      </tr>";
            echo "      <tr>";
            echo "        <td>&nbsp;</td>";
            echo "        <td><div align='center'></div></td>";
            echo "        <td><div align='left'><font color='#FFFF80'>B</font>";
            echo "        <input type='radio' name='chk' value='2'> $choice2<br>";
            echo "      </tr>";
            echo "      <tr>";
            echo "        <td height='24'>&nbsp;</td>";
            echo "        <td><div align='center'></div></td>";
            echo "        <td><font color='#FFFF80'>A</font>";
            echo "        <input type='radio' name='chk' value='3'> $choice3<br>";
            echo "      </tr>";
            echo "      <tr>";
            echo "        <td>&nbsp;</td>";
            echo "        <td><div align='center'></div></td>";
            echo "        <td><div align='left'><font color='#FFFF80'>B</font>";
            echo "        <input type='radio' name='chk' value='4'> $choice4<br>";
            echo "      </tr>";
            echo "    </table>";
            echo "  </div>";
            }

Now im sure after looking at this some may laugh them selves silly, as there is probably a way to do it short and simple.

Thank you all in advance for any help you can give a newbee  :-)

Paul
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.