I would like to use these funky radio buttons though the radio buttons have an id=radio1, id=radio2, id=radio3 etc
I would like all of them to have id-radio1 so it writes the result to radio1 in the database:
Here is how I have normal radio buttons working in the past using the same id and they toggle between one another:
<div class="form-group col-md-12">
<label class="control-label form-check-inline">Gender</label>*
<div class="form-group">
<input type="radio" id="Gender" name="Gender" value="M" required="required" /><label class="control-label">Male</label>
<input type="radio" id="Gender" name="Gender" value="F" required="required" /><label class="control-label">Female</label>
</div>
</div>
$Gender=$_POST["Gender"];
INSERT INTO [dbo].[SubmissionsTBL]
[Gender]
VALUES
(,'".trimText($Gender)."')
Though, with the funky radio buttons chaning from this:
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio1" />
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio2"/>
<label for="radio2">Female</label>
</div>
</div>
to this doesn't work - it doesn't allow me to toggle radio buttons:
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio1" />
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio1"/>
<label for="radio2">Female</label>
</div>
</div>
What is stopping the toggle?
Thank you!
TL;DR: Due to the id and name attribute having the same value in your first example, I believe you may be confusing the two. With the database communication code you put up, it's grabbing the name="Gender" and not the id="Gender".
Additional information about id and class though you might find useful as an internet programmer:
The id attribute can only apply to one element per HTML document. I would suggest using the class attribute instead. The main difference between and id and a class is that a class can be applied to multiple elements.
Here is a working solution to the code you provided:
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio1" class="radio_grp1"/>
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio2" class="radio_grp1"/>
<label for="radio2">Female</label>
</div>
</div>
I used the class .radio_grp1 as the name so that you know that you're referring to a group of radio buttons rather than just one.
Moreover, if you're using a library like bootstrap, it's very common that an element will already have an assigned class. To solve this issue, you can assign a single element multiple classes by adding a space in the string following the class attribute like so:
<input type="radio" name="radio" id="radio2" class="radio radio_grp1"/>
Hope this was useful!
Your code should be changed to something like this. the radio button's name is what is submitted to the back end, and the id is used for front-end things like label association.
id's should always be unique.
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio1" />
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio2"/>
<label for="radio2">Female</label>
</div>
</div>
If by toggling, you mean the normal behavior of radio buttons, then that happens whenever all the radio buttons in the group have the same name.
Related
I am trying to ensure that our forms are accessible.
Looking at the W3C documentation for Radio Groups, oddly their example does not even use input type="radio". I don't understand that at all. I have used the code below in my app, and it would appear that Voiceover reads the form correctly. Am I correct? And why would they you div tags and a lot of JS instead of simple HTML form controls?
<div role="radiogroup"
aria-labelledby="stackedRadioGroup">
<p class="radio-group-label"
id="stackedRadioGroup">Stacked Radio Group Label</p>
<div class="form-check">
<input class="form-check-input"
type="radio"
role="radio"
name="stackedRadiosExample"
id="stackedRadiosExample1"
value="option1"
checked>
<label class="form-check-label"
for="stackedRadiosExample1">
Radio 1
</label>
</div>
<div class="form-check">
<input class="form-check-input"
type="radio"
role="radio"
name="stackedRadiosExample"
id="stackedRadiosExample2"
value="option2">
<label class="form-check-label"
for="stackedRadiosExample2">
Radio 2
</label>
</div>
<div class="form-check">
<input class="form-check-input"
type="radio"
role="radio"
name="stackedRadiosExample"
id="stackedRadiosExample3"
value="option3"
disabled>
<label class="form-check-label"
for="stackedRadiosExample3">
Radio 3 (Disabled)
</label>
</div>
</div>
You can use native input[type='radio'] elements but you will still have to have a role='radiogroup' element to group the different items (a fieldset for instance)
Some people do not use native elements in order to implement custom designs easily.
With Twitter Bootstrap 3.3.7, I am trying to line up multiple questions that have inline radio button answers and have the radio buttons for all questions line up to be displayed nicer for end users.
If this is on a Extra small device, I want the radio buttons to be on the next line.
The trouble I am having is that applying col-sm-6 (or any column size) seems to not work as I expect. The help-block doesn't fully go to the next line, it's stuck under the radio buttons.
I'm looking to be able to use proper Twitter Bootstrap form syntax. Is this possible with the form syntax, or does this require doing it with their own rows/cols?
An example of a question: JSFiddle https://jsfiddle.net/y8j5f0of/
<div class="row">
<div class="form-group">
<label class="col-sm-6">This is an example question</label>
<div class="col-sm-6">
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
</div>
<span class="help-block">This is an example help block that has a lot of text that should start under the question instead of the answer.</span>
</div>
</div>
Answers are lined up, but the output isn't flowing properly.
If I remove the col-sm-6, everything flows as expected but the answers aren't lined up. Also, this doesn't allow the radio buttons to go to their own line for Extra small device.
JSFiddle https://jsfiddle.net/nz36k74o/1/
<div class="row">
<div class="form-group">
<label>This is an example question 1 that is longer than question 2</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
<span class="help-block">This is an example help block that has a lot of text that should start under the question instead of the answer.</span>
</div>
</div>
Output
The help block should really be in a new row. If it is supposed to be underneath the other content, then its not part of the row. That's the basis of the Bootstrap grid system. A basic question block should look like this:
<div class="form-group">
<div class="row">
<label class="col-sm-6">This is an example question 1 that is longer than question 2</label>
<div class="col-sm-6">
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span class="help-block">This is an example help block that has a lot of text that should start under the question instead of the answer.</span>
</div>
</div>
</div>
Check out the fiddle (sorry onlyhad time to do one)
Here is one solution to align the question correctly. It adds in some extra html tags but I believe it solves your issue.
This is the updated fiddle.
https://jsfiddle.net/nz36k74o/3/
<div class="form-group">
<label class="col-sm-6">This is an example question</label>
<div class="col-sm-6">
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<span class="help-block">This is an example help block.</span>
</div>
</div>
I have two radio buttons, No and Yes. By default no is checked. I have css that styles the checked elements. But by default the styles only work if you physically check it. I want to style it right of page load without have to select it. Currently I am stumped. Thanks for your help
HTML
<div class="split">
<input id="contact-no" type="radio" name="contact" value="No" checked="checked">
<label for="contact-no">No</label>
</div>
<div class="split">
<input id="contact-yes" type="radio" name="contact" value="Yes">
<label for="contact-yes">Yes</label>
</div>
CSS
.am-form input[type="radio"] + label:hover, .am-form input[type="radio"]:checked + label{background: rgb(239,58,65);}
What it looks like on page load:
What It should Look like on page load and after you select it:
I had multiple hidden section with the same name/id, so I juts had to customize each one.
<div class="split">
<input id="ns-contact-no" type="radio" name="ns_contact" value="No" checked="checked">
<label for="ns-contact-no">No</label>
</div>
<div class="split">
<input id="fs-contact-yes" type="radio" name="ns_contact" value="Yes">
<label for="fs-contact-yes">Yes</label>
</div>
further down and hidden:
<div class="split">
<input id="bs-contact-no" type="radio" name="bs_contact" value="No" checked="checked">
<label for="bs-contact-no">No</label>
</div>
<div class="split">
<input id="bs-contact-yes" type="radio" name="bs_contact" value="Yes">
<label for="bs-contact-yes">Yes</label>
</div>
In the HTML layout shown in the following screenshot, I want the radio buttons exactly under the Yes and No labels, but the CSS padding property does not seem to apply to the HTML input tag. The code is given.
How can I change the inline style so that the radio buttons are under the Yes and No labels.
JSFiddle here.
<html>
<div style="padding:25px;">
<div style="background-color:#bf5b5b; ">
<label style="padding-left:25px; padding-right:25px;">Yes</label>
<label style="padding-left:25px; padding-right:25px;">No</label>
<label style="padding-left:25px; padding-right:25px;"></label>
</div>
<div id="option_one_div" style="background-color:#74d4dd;">
<input style="padding-left:125px; padding-right:25px;" type="radio" name="radio" value="0">
<input style="padding-left:25px; padding-right:25px;" type="radio" name="radio" value="1">
<label style="padding-left:25px; padding-right:25px;" for="option_one_div">Label of first group of Radio Buttons</label>
</div>
<div id="option_two_div" style="background-color:#36d666;">
<input style="padding-left:25px; padding-right:25px;" type="radio" name="radio" value="0">
<input style="padding-left:25px; padding-right:25px;" type="radio" name="radio" value="1">
<label style="padding-left:25px; padding-right:25px;" for="option_two_div">Label of second group of Radio Buttons</label>
</div>
</div>
</html>
The idea of padding is that it adds space within the element. You appear to be trying to add space outside the element, for which you should be using margin.
This image may help to explain the concept.
(source: w3schools.com)
The point is, to add space around an element you'd normally use margin rather than padding.
On a side note, a lot of people make this mistake when adding padding to the body; they use margin instead and it yields unpredictable results).
Here's an example fiddle using your code, just with margin instead of padding (I modified the pixels to make it work properly).
Put span tag around input tags with left-padding:
Here is the JSFiddle
Here's my Fiddle
<input style="margin-left: 5%; padding-left:25px; padding-right:25px;" type="radio" name="radio" value="0">
<input style="margin-left: 7.5%; padding-left:25px; padding-right:25px;" type="radio" name="radio" value="1">
I used margin-left with percentage values. It looks like what you described you wanted - you can always replace percentage with pixel values if needed.
In your 2nd div i.e.
<div id="option_one_div" style="background-color:#74d4dd;">
the
<input style="padding-left:125px; padding-right:25px;" type="radio" name="radio" value="0">
here padding-left has 125 px. change it to 25 px your prob will be solved.
Hi why not just do this:
<html>
<div>
<div style="background-color:#bf5b5b; width:100%; float:left;">
<label style="width:15%; padding-left:3%">Yes<input type="radio" name="radio" value="0"></label>
<label style="width:15%;">No<input type="radio" name="radio" value="0"></label>
<label style="width:60%;">Label of first group of Radio Buttons</label>
</div>
<div style="background-color:#74d4dd; width:100%; float:left;">
<label style="width:15%; padding-left:3%">Yes<input type="radio" name="radio" value="0"></label>
<label style="width:15%;">No<input type="radio" name="radio" value="0"></label>
<label style="width:60%;">Label of teo group of Radio Buttons</label>
</div>
<div style="background-color:#36d666; width:100%; float:left;">
<label style="width:15%; padding-left:3%">Yes<input type="radio" name="radio" value="0"></label>
<label style="width:15%;">No<input type="radio" name="radio" value="0"></label>
<label style="width:60%;">Label of three group of Radio Buttons</label>
</div>
</div>
</html>
Then just add some # media css classes to make it full mobile responsive and stack-able too.
This will offer much more to you prospective site users as they can view it from their mobile devices with as much ease as they can from a pc.
I have this code:
<div class="divpere" >
<div class="divfille1" ><label>CIVILITE:</label></div>
<div class="divfille2" >
<input type="radio" ID="mademoiselle" runat="server" >Mademoiselle</input>
<input type="radio" ID="madame" runat="server">Madame</input>
<input type="radio" ID="monsieur" runat="server">Monsieur</input>
</div>
</div>
It's a labale and a list of radio buttons, when i try to check one of this radio button, it still not checked!!
What is the reason of this?
How can i fix my snippet?
Demo Fiddle
<div class="divpere" >
<div class="divfille1" ><label>CIVILITE:</label></div>
<div class="divfille2" >
<input name="samename" type="radio" id="mademoiselle" runat="server" /><label for="mademoiselle"> Mademoiselle</label>
<input name="samename" type="radio" id="madame" runat="server"/><label for="madame">Madame</label>
<input name="samename" type="radio" id="monsieur" runat="server"/><label for="monsieur">Monsieur</label>
</div>
</div>
You should mention the name attribute for your radio buttons and Don't forget to mention the same name values for all three radio buttons...