Jump to content

How to apply a checked attribute to multiple radio inputs fields


eldan88

Recommended Posts

I am echoing out 2 radio input fields in a foreach statement. I would like to have the first option checked in all the radio input fields that gets echoed out.

 

But for some reason it marks the radio input field "checked" all the way in the bottom. (The last one)

 

How can I make it so that every input field that gets echoed out will be marked checked?

 

Below is my code. Thank you for your help

foreach ($menu_cat_options as  $menu_cat_option){

<input type="radio"  checked="checked" name="display_type" value="radio" >Radio
 <br>
<input type="radio"  name="display_type" value="checkbox">Check Box
}

You can't have more than one radio button checked in the same group (ie, with the same name). Use checkboxes instead.

Note that you need to change the name to "display_type[]": those added []s mean that $_POST["display_type"] will be an array of what was checked. Without the []s you'll only get one value.

Archived

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

×
×
  • Create New...

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.