Jump to content


Photo

Use of radio buttons in php


  • Please log in to reply
2 replies to this topic

#1 stern

stern
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 11 October 2006 - 06:41 PM

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


#2 mATOK

mATOK
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts
  • LocationToronto, Ontario

Posted 11 October 2006 - 06:55 PM

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>


"Not everything that counts can be counted, and not everything that can be counted counts."

W3 Web Tutorials | Check Your html | CSS layout techniques | ALA | Zen Garden | CSS Links

Navs with flavor | CSS Playground | CSS boxes

#3 stern

stern
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 11 October 2006 - 07:19 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users