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"> </label>
<input type="radio" name="colsel" id="colsel" value= "Sort" checked="checked" />
<label id="color_black"> </label>
<input type="radio" name="colsel" id="colsel" value= "Grå" />
<label id="color_grey"> </label>
<input type="radio" name="colsel" id="colsel" value="Lys rød" />
<label id="color_lightred"> </label>
<input type="radio" name="colsel" id="colsel" value="Rød" />
<label id="color_red"> </label>
<input type="radio" name="colsel" id="colsel" value="Pink" />
<label id="color_pink"> </label><br />
<input type="radio" name="colsel" id="colsel"value="Blå" />
<label id="color_blue"> </label>
<input type="radio" name="colsel" id="colsel" value="Lys blå" />
<label id="color_lightblue"> </label>
<input type="radio" name="colsel" id="colsel" value="Grøn" />
<label id="color_green"> </label>
<input type="radio" name="colsel" id="colsel" value="Lime" />
<label id="color_lime"> </label>
<input type="radio" name="colsel" id="colsel" value="Gul" />
<label id="color_yellow"> </label>
<input type="radio" name="colsel" id="colsel" value="Orange" />
<label id="color_orange"> </label><br />
<input type="radio" name="colsel" id="colsel" value="Lilla" />
<label id="color_purple"> </label>
<input type="radio" name="colsel" id="colsel" value="Sølv" />
<label id="color_silver"> </label>
<input type="radio" name="colsel" id="colsel" value="Guld" />
<label id="color_gold"> </label>
</form>
</div>
<?php
$_SESSION["color"] = $_POST["colsel"];
// $_SESSION["size"] = 'sizetable';
?>
Problems understanding how to use radio buttons.
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Problems understanding how to use radio buttons.
Maybe add a submit button at the bottom of the form:
<input type="submit" name="submit" value="Submit" />
<input type="submit" name="submit" value="Submit" />
(#10850)
- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: Problems understanding how to use radio buttons.
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:
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
change it to
HTH,
Mecha Godzilla
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"];Code: Select all
<input type="radio" name="colsel" id="colsel" value= "Hvid" />
<label id="color_white"> </label> Code: Select all
<input type="radio" name="colsel" id="colsel" value= "Hvid" />
<label id="color_white"> Hvid </label> Mecha Godzilla