Jump to content

Archived

This topic is now archived and is closed to further replies.

stern

Use of radio buttons in php

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

Share this post


Link to post
Share on other sites
I think that you need these buttons to be a part of a form

<form name="something" action="file-with-switch" methos="get"> // or method="post"

-- radio buttons

<input type="Submit" value="Submit">
</form>

Share this post


Link to post
Share on other sites
That did the trick  :-)  thanks you so much for the help. I must really applaud all the people here, as you are all making it a lot easier for newbee's like me to learn a lot faster  :-)

Thank you all :D

Share this post


Link to post
Share on other sites

×

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.