1

I am trying to solve how to use css generated background in conjunction with form radio buttons.

I have a list of option produces from a PHP array which displays each row (description) and two radio button with a value of 0 or 1.

I have this woth where there is only one item but when I use the same code for a list only the first item (radio button) in the list works.

Is there a way of making all the radio buttons in the list work.

Many thanks for any help you can provide.

This is the code I am working with:

<?php do { ?>
<tr>
<td class="form_sub_headers_left"><?php print $row_BreakDown['FeedBackBreakDown']; ?></td>
<td>&nbsp;</td>
<td align="center">
<input type="radio" name="BreakDown" value="0" id="BreakDown_0" class="styled"/>
<label for="BreakDown_0">Bad</label>
</td>
<td align="center">
<input type="radio" name="BreakDown" value="1" id="BreakDown_1" class="styled" />
<label for="BreakDown_1">Good</label>
</td>
</tr>
<?php } while ($row_BreakDown = mysql_fetch_assoc($BreakDown)); ?>

The CSS file is:

input[type=radio], input[type=checkbox] {
display:none;
}

input[type=radio] + label, input[type=checkbox] + label {
display:inline-block;
margin:-2px;
padding: 4px 12px;
margin-bottom: 0;
font-size: 14px;
line-height: 20px;
color: #333;
text-align: center;
text-shadow: 0 1px 1px rgba(255,255,255,0.75);
vertical-align: middle;
cursor: pointer;
background-color: #f5f5f5;
background-image: -moz-linear-gradient(top,#fff,#e6e6e6);
background-image: -webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));
background-image: -webkit-linear-gradient(top,#fff,#e6e6e6);
background-image: -o-linear-gradient(top,#fff,#e6e6e6);
background-image: linear-gradient(to bottom,#fff,#e6e6e6);
background-repeat: repeat-x;
border: 1px solid #ccc;
border-color: #e6e6e6 #e6e6e6 #bfbfbf;
border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);
border-bottom-color: #b3b3b3;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff',endColorstr='#ffe6e6e6',GradientType=0);
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
-webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);
-moz-box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);
box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);
}

input[type=radio]:checked + label, input[type=checkbox]:checked + label{
color: #FFF;
background-image: none;
outline: 1;
-webkit-box-shadow: inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);
-moz-box-shadow: inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);
box-shadow: inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);
background-color:#CC0000;
}

Blackbox

DCJones
  • 3,121
  • 5
  • 31
  • 53
  • http://stackoverflow.com/questions/17541614/use-image-instead-of-radio-button – SaggingRufus Aug 21 '15 at 16:35
  • That solution is fine if the radio buttons are hard coded, in my case they are generated from a MySQL query. depending on the row result I need to have each row have working buttons. – DCJones Aug 21 '15 at 17:03
  • same concept, just style tags in your HTML – SaggingRufus Aug 21 '15 at 17:19
  • Hi @SaggingRufus , its not exactly the same concept. In my case I have rows of data from an MySQL query. I need to have two radio buttons per row returned by the query. The example you point to has the rows and radio button hard coded. The issue is I think, each radio button has an name and an id. But within the WHILE loop all the radio buttons are given the same id. Is there a way to solve this problem. Again many thanks for any help. – DCJones Aug 22 '15 at 13:51

0 Answers0