Solved

radio buttons id or name controls

Posted on 2011-09-14
15
311 Views
Last Modified: 2012-05-12
i have a group of radio buttons each have different names and ids is this correct?

im asking this because when i display it in the browser and select radio buttons from an array of 3 objects it allows to select all buttons on the 3 objects.

i also have a array number plugged into the element name and id


if($DefaultPic == 'Y') 
			{
			echo '<input type="radio" name="Default0[',$RecordId,']" id="Default0',$RecordId,'" value="Y" checked="checked"  />';
			}
			else 
			{
			echo '<input type="radio" name="Default0[',$RecordId,']" id="Default0',$RecordId,'" value="N"  />';
			}

Open in new window


thanks in advance for your help!
0
Comment
Question by:only1wizard
  • 5
  • 4
  • 3
  • +1
15 Comments
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 36536434
Radio buttons and checkboxes have several similarities, the principal difference being that only zero or one radio button of the same name (not id) can be fired at once.  This article might offer some ideas (I am not sure I understand what you want to achieve).
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_5450-Common-Sense-Examples-Using-Checkboxes-with-HTML-JavaScript-and-PHP.html
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 36536445
I see only two radiobuttons printed alternativelly... However give them the same name to make them mutually exclusive or post more code if my answer is not enough :-)
0
 

Author Comment

by:only1wizard
ID: 36536448
im thinking that i need to have the ids in the array and not the name of the radio?
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 36536450
Oooops, didn't refresh...
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 36536470
name has to have array notation : myname[]. In your case you have to call them

name="Default0[',$RecordId,'][]"
0
 

Author Comment

by:only1wizard
ID: 36536546
what is the additional [] for?

here the logic:

i query records returns max 25 records so im going to have a max of 25 records with the

here would be the radio elements out put for up to 25

name="Default01" id="Default01"

name="Default02" id="Default02"

name="Default025" id="Default025"

im using the array to keep them in a group shouldnt i keep them in the same array by id because they are all the same name with out the number?
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 250 total points
ID: 36536568
I'm sorry, I've confused radiobuttons and checkboxes: checkboxes has to have the addtional brackets. To make radiobuttons are mutully exclusive you have to give them the same name

name="Default" id="Default01"

name="Default" id="Default02"

name="Default" id="Default025"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:maeltar
ID: 36537083
Using the format

name="Default01" id="Default01"

name="Default02" id="Default02"

name="Default025" id="Default025"

Would give you 3 groups of buttons.

For your 25 (approx) returned records do you want then in the same group, as in, do you only want to give 1 option for selection ?

If so you should have something like this :

name="Default" id="Default01"

name="Default" id="Default02"

...

name="Default" id="Default025"

So, the NAME of the buttons would be the same, giving a group with only one selectable in that NAMED group, and the id would change as would the value returned..

<input type="radio" name="Default" id="Default01" value="widget1" />

<input type="radio" name="Default" id="Default02" value="widget2" />

...

<input type="radio" name="Default" id="Default025" value="widget25" />
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 36537108
@maeltar: have you read my post ID:36536568 posted almost 1 hour before yours?
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36537117
... have the ids in the array and not the name of the radio?

The "name" attribute of the input tag is used as the array key in the request ($_GET or $_POST).

For radios to work correctly, you need to have one of more input tags of type="radio" with the same name attribute.  Make a Google search for "html radio button" and read a few of the links.  You are not the first person to have this question!

Best regards, ~Ray
0
 
LVL 11

Expert Comment

by:maeltar
ID: 36537124
@marqusG, yes I did, and expanded on it with some more detailed explanation.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36538821
Amazing.  Did you not understand that this question was completely answered by the first post?

Radio buttons and checkboxes have several similarities, the principal difference being that only zero or one radio button of the same name (not id) can be fired at once.

Please consider getting something of a foundation in how HTML and PHP work together.  The introductory tutorial here is a good place to start.
http://www.tizag.com/phpT/examples/formex.php
0
 

Author Comment

by:only1wizard
ID: 36538867
you listed a link to checkboxes is as to why i did not select yours as an answer i will do a partial.
0
 

Author Closing Comment

by:only1wizard
ID: 36539667
thanks for your help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now