Page 1 of 1

Problems understanding how to use radio buttons.

Posted: Sat Feb 09, 2013 5:53 am
by bbo
I'm trying to get the selected radiobutton value of a group of radiobuttons with no luck. I wonder if anyone could tell me what i'm doing wrong here.
I just want to point out that I'm a newbee to PHP coding.

Here is the code:

<div style="position: absolute; left: 9px; top: 412px; width: 364px; height: 85px;" align="left">
<form id="form1" name="form1" method="post" action="product.php">
<input type="radio" name="colsel" id="colsel" value= "Hvid" />
<label id="color_white"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value= "Sort" checked="checked" />
<label id="color_black"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value= "Grå" />
<label id="color_grey"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value="Lys rød" />
<label id="color_lightred"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value="Rød" />
<label id="color_red"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value="Pink" />
<label id="color_pink"> &nbsp; &nbsp; </label><br />
<input type="radio" name="colsel" id="colsel"value="Blå" />
<label id="color_blue"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value="Lys blå" />
<label id="color_lightblue"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value="Grøn" />
<label id="color_green"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value="Lime" />
<label id="color_lime"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value="Gul" />
<label id="color_yellow"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value="Orange" />
<label id="color_orange"> &nbsp; &nbsp; </label><br />
<input type="radio" name="colsel" id="colsel" value="Lilla" />
<label id="color_purple"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value="Sølv" />
<label id="color_silver"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
<input type="radio" name="colsel" id="colsel" value="Guld" />
<label id="color_gold"> &nbsp; &nbsp; &nbsp; </label>
</form>
</div>
<?php
$_SESSION["color"] = $_POST["colsel"];
// $_SESSION["size"] = 'sizetable';
?>

Re: Problems understanding how to use radio buttons.

Posted: Sat Feb 09, 2013 12:38 pm
by Christopher
Maybe add a submit button at the bottom of the form:

<input type="submit" name="submit" value="Submit" />

Re: Problems understanding how to use radio buttons.

Posted: Sat Feb 09, 2013 3:43 pm
by mecha_godzilla
Hi,

Just to add to Christopher's point, you're not actually doing anything with the radio button value except placing it in a session value that you can't see - for testing purposes you should echo() it out to the browser like this:

Code: Select all

$_SESSION["color"] = $_POST["colsel"];
echo 'Here is the color: ' . $_SESSION["color"];
Also, you don't know which option you're selecting on the form because there are no labels next to the radio buttons. Where you have

Code: Select all

<input type="radio" name="colsel" id="colsel" value= "Hvid" />
<label id="color_white"> &nbsp; &nbsp; </label>&nbsp; &nbsp;
change it to

Code: Select all

<input type="radio" name="colsel" id="colsel" value= "Hvid" />
<label id="color_white"> &nbsp; Hvid &nbsp; </label>&nbsp; &nbsp;
HTH,

Mecha Godzilla