Jump to content

How to apply a checked attribute to multiple radio inputs fields


Go to solution Solved by requinix,

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
}
  • Solution

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.