How should I group several radio inputs? - html

When in a form I have several radio inputs that make a single control (example below), what's the most semantic way to group them together?
<form>
<!-- Single radio control made of 3 radio inputs -->
<input type="radio" name="X" value="A" />
<input type="radio" name="X" value="B" />
<input type="radio" name="X" value="C" />
<!-- Some other control -->
<input type="text" name="Y" value="D" />
</form>
I know I can enclose them in a paragraph (<p>..</p>), but I wonder if maybe list (<ul>..</ul>) would be more semantic approach?

You can group together by using fieldset
.radio_button{
list-style-type: none;
}
<form>
<h1>Testing Form Radio buttons</h1>
<fieldset>
<legend>Title</legend>
<ul>
<li class="radio_button">
<label for="title_1">
<input type="radio" id="title_1" name="title" value="M." />
Mister
</label>
</li>
<li class="radio_button">
<label for="title_2">
<input type="radio" id="title_2" name="title" value="Ms." />
Miss
</label>
</li>
</ul>
</fieldset>
</section>
</form>

Try this:
<form>
<!-- Single radio control made of 3 radio inputs -->
<ul>
<li>
<input type="radio" name="X" value="A" />A
</li>
<li>
<input type="radio" name="X" value="B" />B
</li>
<li>
<input type="radio" name="X" value="C" />C
</li>
</ul>
<input type="text" name="Y" value="D" />
</form>

A good way would be using the bootstrap lib and format your forms with bootstrap
: Bootstrap form inputs

You can use the name field same if you want to get only 1 value selected,
And only selected field's value (value = "A") will be submitted.
You can group them using css styles. W3.css is a nice library like bootstrap.
W3.css examples

Related

Mixing radio with checked button in html

I want to mix radio and checked button like i design B here https://ux.stackexchange.com/questions/70531/using-mixed-radio-and-checkbox-buttons-is-there-any-efficiency-or-usability-ga
But i just could figure out how to do separately:
<input class="radio-input" type="radio" name="result" value="names" />
<label class="radio-label">Get names of people starting with..</label>
<input type="checkbox" id="A" name="name[]" value="n">
<label for="A">A</label>
<input type="checkbox" id="B" name="name[]" value="n">
<label for="B">B</label>
How can i do this like in design B?
You would have to put them into separate divs, and then align them to be next to each other with CSS styling.
.no-bullets {
list-style:none;
}
<h2>first row</h1>
<ul class = "no-bullets">
<li> <input type="radio" name="name"></li>
<li> <input type="radio" name="name"></li>
<ul class = "no-bullets">
<li><input type="checkbox" name="sex"></li>
<li><input type="checkbox" name="sex"></li>
<li><input type="checkbox" name="sex"></li>
</ul>
</ul>
</div>

How to make group of radio buttons (generated dynamically) work independently?

What I intend to do is to make each radio button group work independetly.
Please refer this http://codepen.io/anon/pen/tkqew
I want to select an option from each line, but it is selecting only one option.
In future work I want to generate this whole icon thread dynamically so please if you could suggest how I can do that.
A radio button group is created by specifying the same name attribute for the radio buttons in a group. Simply give another common name for the radio buttons in the second line so that they'll act as a different group...
Radio Button activity relies on the names. If you want a group of Radiobuttons just name the group.
<input type="radio" name="optionsRadios" class="optionsRadios2" value="option1" checked="checked" title="Nenhum">
{...}
<input type="radio" name="optionsRadios2" class="optionsRadios2" value="option1" checked="checked" title="Nenhum">
If you are using loops to creating those radio buttons, use the index (as a prefix) in the radio button name.
Like:
<input type="radio" name="first_1">
<input type="radio" name="first_2">
1 and 2 is the index here..
You can select more then one option in radio button but dont put the radio button name same as other button, every button should have unique name.
like this
<input type="radio" name="button1">
<input type="radio" name="button2">
also visit your link i have changed it
You need to give each "set" of radio buttons distinct names:
<div class="icon-thread">
<ul>
<li>
<input type="radio" name="optionsRadios_set1" class="optionsRadios2" value="option1" checked="checked" title="Nenhum">
<label class="radio" for="optionsRadios2"><i class="icon-ban-circle icon-stack-base text-error"></i></label>
</li>
<li>
<input type="radio" name="optionsRadios_set1" class="optionsRadios2" value="option2">
<label class="radio" for="optionsRadios2"><i class="icon-fixed-width icon-moon"></i></label>
</li>
<li>
<input type="radio" name="optionsRadios_set1" class="optionsRadios2" value="option3">
<label class="radio" for="optionsRadios2"><i class="icon-fixed-width icon-plane"></i></label>
</li>
</ul>
</div>
<div class="icon-thread">
<ul>
<li>
<input type="radio" name="optionsRadios_set2" class="optionsRadios2" value="option1" checked="checked" title="Nenhum">
<label class="radio" for="optionsRadios2"><i class="icon-ban-circle icon-stack-base text-error"></i></label>
</li>
<li>
<input type="radio" name="optionsRadios_set2" class="optionsRadios2" value="option2">
<label class="radio" for="optionsRadios2"><i class="icon-fixed-width icon-moon"></i></label>
</li>
<li>
<input type="radio" name="optionsRadios_set2" class="optionsRadios2" value="option3">
<label class="radio" for="optionsRadios2"><i class="icon-fixed-width icon-plane"></i></label>
</li>
</ul>
</div>
Edit: as an aside, you've misused the for attribute in the label. That should match the id of the input element.

Accessibilty for WCAG Standards - How to handle a label within a label

I'm trying to figure out how to mark up some code using WCAG standards, but it's a little complicated when I run into this situation:
<div class="form-group">
<label>Entry Method</label>
<div>
<label>
<input type="radio" /> Upload file
</label>
<label>
<input type="radio" /> Enter Manually
</label>
<label>
<input type="radio" /> Load Template
</label>
</div>
</div>
What do I do with the first "label"? How do I use "for" and "id" in this scenario?
A label accompanies a single form field, rather than a group of fields. Grouping form fields is achieved using a fieldset instead of a div, which is accompanied by a legend instead of a label:
<fieldset class="form-group">
<legend>Entry Method</legend>
<div>
<label>
<input type="radio" /> Upload file
</label>
<label>
<input type="radio" /> Enter Manually
</label>
<label>
<input type="radio" /> Load Template
</label>
</div>
</fieldset>
See H71 of WCAG 2.0 for a detailed write-up.

change form action with radio buttons

I would like to implement something similar to a google search with radio buttons. Depending on the radio button selected, would change the type of search (search,images,video, etc).
Right now I have:
<div id ="searchtext">
<form method="get" id ="searchbox" action="http://www.google.com/search"/>
<input type="text" name="q" size="30" class="searchtext" maxlength="255" value="" />
<input type="image" value="Search" class="searchbutton" src="images/searchbar/searchbutton.png"/>
<br/>
</div>
<div id="radiosearch">
<input type="radio" name="radiosearch" onclick="document.searchbox.action='http://www.google.com/search?q=';" checked="checked"/> Web
<input type="radio" name="radiosearch" onclick="document.searchbox.action='http://images.google.com/images?q=';"/>Images
<input type="radio" name="radiosearch" onclick="document.searchbox.action='http://maps.google.com/maps?hl=en&tab=wl?q=';"/>Maps
<input type="radio" name="radiosearch" onclick="document.searchbox.action='http://www.youtube.com/results?q=';"/>Youtube
<span class = "class1">
Change Theme
</span>
</div>
However, clicking on the radio boxes is not changing the form action. Any Ideas?
Try
<input type="radio" name="radiosearch" onclick="document.getElementById('searchbox').action='http://www.google.com/search?q=';" checked="checked"/> Web
<input type="radio" name="radiosearch" onclick="document.getElementById('searchbox').action='http://images.google.com/images?q=';"/>Images
<input type="radio" name="radiosearch" onclick="document.getElementById('searchbox').action='http://maps.google.com/maps?hl=en&tab=wl?q=';"/>Maps
<input type="radio" name="radiosearch" onclick="document.getElementById('searchbox').action='http://www.youtube.com/results?q=';"/>Youtube

Jquery Mobile multi select list with checkboxes

Building JQM App
Need to display a scrolling list of nearly 200 items with check boxes next to each one that will check/uncheck as the user makes their selection.
looking for a clean way of implementing said list using JQM if possible, but I don't see anything in their documentation/demos.
is there something useable in JQM or should I just roll my own?
Thanks.
Example:
http://jsfiddle.net/qvx85/14/
JS
// Add 200 list items
for( i=0; i < 200; i++){
createListItems(i, 'hello-'+i);
}
// add jQM markup
$('#theList').trigger('create');
// refresh the list
$('#theList').listview('refresh');
function createListItems(number, option) {
var item = '<li><h3>Question '+number+' using Checkbox Options</h3><p><strong>Do you '+option+'?</strong></p><p>Please select an option</p><p class="ui-li-aside"><fieldset data-role="controlgroup" data-type="horizontal"><input type="checkbox" name="q'+number+'" id="q'+number+'-'+option+'" class="custom" /><label for="q'+number+'-'+option+'">'+option+'</label></fieldset></p></li>';
$('#theList').append(item);
}
HTML
<div data-role="page" id="home">
<div data-role="content">
<h2>List of Questions</h2>
<ul data-role="listview" data-inset="true" id="theList">
<li>
<h3>Question 1 using Radio Options</h3>
<p><strong>Do you agree?</strong></p>
<p>Please select an option</p>
<p class="ui-li-aside">
<fieldset data-role="controlgroup" data-type="horizontal">
<input type="radio" name="q1" id="q1-agree" value="agree" />
<label for="q1-agree">Agree</label>
<input type="radio" name="q1" id="q1-disagree" value="disagree" />
<label for="q1-disagree">Disagree</label>
</fieldset>
</p>
</li>
<li>
<h3>Question 2 using Radio Options</h3>
<p><strong>Another question</strong></p>
<p>Please select an answer</p>
<p class="ui-li-aside">
<fieldset data-role="controlgroup" data-type="horizontal">
<input type="radio" name="q2" id="q2-agree" value="agree" />
<label for="q2-agree">Agree</label>
<input type="radio" name="q2" id="q2-disagree" value="disagree" />
<label for="q2-disagree">Disagree</label>
</fieldset>
</p>
</li>
<li>
<h3>Question 3 using Checkbox Options</h3>
<p><strong>Do you agree?</strong></p>
<p>Please tap to select the option</p>
<p class="ui-li-aside">
<fieldset data-role="controlgroup" data-type="horizontal">
<input type="checkbox" name="q3" id="q3-agree" class="custom" />
<label for="q3-agree">Agree</label>
</fieldset>
</p>
</li>
</ul>
</div>
</div>