What is the most accessible way to split a single radio form (same name) into groups? For example, choosing a time with the groups Today or Tomorrow?
Perhaps split them into two fieldsets?
<h3>Select a time and we'll give you a call</h3>
<form>
<fieldset>
<legend>Today</legend>
<input type="radio" name="phone" id="a" value="a"/>
<label for="a">9am</label>
<input type="radio" name="phone" id="b" value="b"/>
<label for="b">12pm</label>
<input type="radio" name="phone" id="c" value="c"/>
<label for="c">5pm</label>
</fieldset>
<fieldset>
<legend>Tomorrow</legend>
<input type="radio" name="phone" id="d" value="d"/>
<label for="d">9am</label>
<input type="radio" name="phone" id="e" value="e"/>
<label for="e">12pm</label>
<input type="radio" name="phone" id="f" value="f"/>
<label for="f">5pm</label>
</fieldset>
</form>
The best approach seems to be using multiple fieldsets and in this particular example we want to clarify the legends as Graham Ritchie suggested. VoiceOver repeats the legend on each radio so it was redundant to add it to the label as well.
<h3>Select a time and we'll give you a call</h3>
<form>
<fieldset>
<legend><span class="visually-hidden">Call me</span> Today</legend>
<input type="radio" name="phone" id="a" value="a"/>
<label for="a">9am</label>
<input type="radio" name="phone" id="b" value="b"/>
<label for="b">12pm</label>
</fieldset>
<fieldset>
<legend><span class="visually-hidden">Call me</span> Tomorrow</legend>
<input type="radio" name="phone" id="d" value="d"/>
<label for="d">9am</label>
<input type="radio" name="phone" id="e" value="e"/>
<label for="e">12pm</label>
</fieldset>
</form>
I updated the answer. Not sure you can do this with radio buttons but checkboxes and some javascript should do the trick.
function group1(e){
var id = e.target.id;
var boxes = document.getElementsByTagName('input');
for(let i=0;i<3;i++){
if (boxes[i].id != id)boxes[i].checked=false;
}
}
function group2(e){
var id = e.target.id;
var boxes = document.getElementsByTagName('input');
for(let i=3;i<6;i++){
if (boxes[i].id != id)boxes[i].checked=false;
}
}
<h3>Select a time and we'll give you a call</h3>
<form>
<fieldset>
<legend>Today</legend>
<input type="checkbox" name="phone[]" onClick='group1(event)' id="a" value="a"/>
<label for="a">9am</label>
<input type="checkbox" name="phone[]" onClick='group1(event)' id="b" value="b"/>
<label for="b">12pm</label>
<input type="checkbox" name="phone[]" onClick='group1(event)' id="c" value="c"/>
<label for="c">5pm</label>
</fieldset>
<fieldset>
<legend>Tomorrow</legend>
<input type="checkbox" name="phone[]" onClick='group2(event)' id="d" value="d"/>
<label for="d">9am</label>
<input type="checkbox" name="phone[]" onClick='group2(event)' id="e" value="e"/>
<label for="e">12pm</label>
<input type="checkbox" name="phone[]" onClick='group2(event)' id="f" value="f"/>
<label for="f">5pm</label>
</fieldset>
</form>
Related
I have a form on a page in which the fieldsets create another scrollbar in the page, and makes the form scrollable. This is so weird, and its even weirder that I cant find any sort of information or solution on this anywhere. It should just continue on in the page, I have no size restriction for the form.
Here is my HTML for the form
<form>
<fieldset>
<legend>Customer Information:</legend>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="area">Please describe your concern:</label><br>
<textarea name="area" id="area" rows="5" cols="30"></textarea><br><br>
</fieldset><br>
<fieldset>
<legend>Product Information:</legend>
<label for="pname">Product name:</label>
<input type="text" id="pname" name="pname"><br><br>
<label for="date">Date of Purchase:</label>
<input type="date" id="date" name="date"><br><br>
<label>Select your warranty plan:</label> <br>
<input type="radio" id="none" name="plan" value="none">
<label for="none">None</label><br>
<input type="radio" id="six" name="plan" value="six">
<label for="css">6 Months</label><br>
<input type="radio" id="twelve" name="plan" value="twelve">
<label for="javascript">12 Months</label><br>
<input type="radio" id="eighteen" name="plan" value="eighteen">
<label for="css">18 Months</label><br>
<input type="radio" id="twentyfour" name="plan" value="twentyfour">
<label for="javascript">24 Months</label><br><br>
<label>Select which THE BOARD SHOP locations you have shopped at: </label><br>
<input type="checkbox" id="Toronto" name="Toronto" value="Toronto">
<label for="Toronto"> Toronto</label><br>
<input type="checkbox" id="Montreal" name="Montreal" value="Montreal">
<label for="Montreal"> Montreal</label><br>
<input type="checkbox" id="California" name="California" value="California">
<label for="California"> California</label><br>
<input type="checkbox" id="New York" name="New York" value="New York">
<label for="New York"> New York</label><br>
<input type="checkbox" id="Cairo" name="Cairo" value="Cairo">
<label for="Cairo"> Cairo</label><br>
</fieldset><br>
<input type="submit" value="Submit" id="submit">
</form>
and the CSS
form {
margin: 0 auto;
width: 50%;
}
textarea {
resize: none;
}
label,
legend,
input {
font-family: "Kanit", sans-serif;
}
I need some help. The question is how to put in the "for" attribute two "id" parameters from input? or how a can do with label in other way?
<label for="address">Address: </label>
<input class="form-style" type="text" name="address" id="address"/>
<label for="gender1 gender2">Gender:</label>
<input class="gender" type="radio" name="gender" id="gender1" value="Male"/>Male
<input class="gender" type="radio" name="gender" id="gender2" value="Female"/>Female
You can't. A label is for a single form control. Each radio button should have its own label.
Use a fieldset to group multiple controls, and a legend to describe the controls with it in.
<label for="address">Address: </label>
<input class="form-style" type="text" name="address" id="address" />
<fieldset>
<legend>Gender</legend>
<input class="gender" type="radio" name="gender" id="gender1" value="Male" />
<label for="gender1">Male</label>
<input class="gender" type="radio" name="gender" id="gender2" value="Female" />
<label for="gender2">Female</label>
<input class="gender" type="radio" name="gender" id="gender3" value="Other" />
<label for="gender3">Other</label>
<input class="gender" type="radio" name="gender" id="gender4" value="Prefer not to say" />
<label for="gender4">Prefer not to say</label>
</fieldset>
The below HTML code i have allows multiple selection of radio button ? How do i limit it so that only one can be chooses at a time from the list
<fieldset data-role="controlgroup">
<legend></legend>
<label for="Arrived/Left">Arrived/Left Destination</label>
<input type="radio" name="Arrived/Left" id="Arrived/Left" value="Arrived/Left">
<label for="Delayed">Delayed</label>
<input type="radio" name="Delayed" id="Delayed" value="Delayed">
<label for="Canceled">Canceled</label>
<input type="radio" name="Canceled" id="Canceled" value="Canceled">
<label for="getupdate">Post to Get Update ?</label>
<input type="radio" name="getupdate" id="getupdate" value="getupdate">
<label for="Other">Other</label>
<input type="radio" name="Other" id="Other" value="Other">
</fieldset>
First this is not jQuery.. this is HTML..
Second you can do that by giving all the radio buttons of the same group (where you want only one to be selected) the same name..
<fieldset data-role="controlgroup">
<legend></legend>
<label for="Arrived/Left">Arrived/Left Destination</label>
<input type="radio" name="status" id="Arrived/Left" value="Arrived/Left">
<label for="Delayed">Delayed</label>
<input type="radio" name="status" id="Delayed" value="Delayed">
<label for="Canceled">Canceled</label>
<input type="radio" name="status" id="Canceled" value="Canceled">
<label for="getupdate">Post to Get Update ?</label>
<input type="radio" name="status" id="getupdate" value="getupdate">
<label for="Other">Other</label>
<input type="radio" name="status" id="Other" value="Other">
</fieldset>
use name attribute to group your radio button
<fieldset data-role="controlgroup">
<legend></legend>
<label for="Arrived/Left">Arrived/Left Destination</label>
<input type="radio" name="status" id="Arrived/Left" value="Arrived/Left">
<label for="Delayed">Delayed</label>
<input type="radio" name="status" id="Delayed" value="Delayed">
<label for="Canceled">Canceled</label>
<input type="radio" name="status" id="Canceled" value="Canceled">
<label for="getupdate">Post to Get Update ?</label>
<input type="radio" name="status" id="getupdate" value="getupdate">
<label for="Other">Other</label>
<input type="radio" name="status" id="Other" value="Other">
</fieldset>
You define radio button groups with the name property (radio buttons with the same name belong to the same group).
You are having a different name for each of your radio. Change the names of all the input radio to a single name. The radios having the same name will behave as a single group which is what your requirement.
*You haven't closed the input tags.
Hope this helps.
If i have two inputs of type text with the same name, like this:
<input type="text" name="task" id="task1" value="begin">
<input type="text" name="task" id="task2" value="end">
When i submit the form task is automatically sent as an array (task[0]='begin', task[1]='end').
This is very useful for many reasons, for instance i don't have to worry about serializing the result, I can use a sortable to re-sort and when I submit it's already in the right order.
But if i want to use radio buttons, i have to use several inputs with the same name already.
Is there a way I could keep this functionality with radio buttons?
For instance:
<input type="text" name="task" id="task1" value="begin">
<input type="radio" name="time" id="time11" value="early" checked="checked">
<input type="radio" name="time" id="time12" value="noon">
<input type="radio" name="time" id="time13" value="late">
<input type="text" name="task" id="task2" value="end">
<input type="radio" name="time" id="time21" value="early">
<input type="radio" name="time" id="time22" value="noon" checked="checked">
<input type="radio" name="time" id="time23" value="late">
I want that when submitted i get time[0]='early' and time[1]='noon'
Try this:
<input type="text" name="task[0]" id="task1" value="begin">
<input type="radio" name="time[0]" id="time11" value="early" checked="checked">
<input type="radio" name="time[0]" id="time12" value="noon">
<input type="radio" name="time[0]" id="time13" value="late">
<input type="text" name="task[1]" id="task2" value="end">
<input type="radio" name="time[1]" id="time21" value="early">
<input type="radio" name="time[1]" id="time22" value="noon" checked="checked">
<input type="radio" name="time[1]" id="time23" value="late">
Then you'd get: task[0]=begin, time[0]=early, task[1]=end and time[1]=noon.
Hello Can you tell why I am allowed to select two radio buttons in this code
<html>
<head><title>Survey</title>
<body>
<h3>Please Enter the following Information: </h3>
<form method= "post" action="/~fmccown/cgi-bin/printinfo.cgi">
<input type ="hidden" name="input-source" value="survey2.html" />
<p>
Name: <input type="text" name="name" size="30" />
</p><p>
Classification:
<select name="class">
<option>Freshman</option>
<option selected="selected">Sophomore</option>
<option>Junior</option>
<option>Senior</option>
</select>
</p><p>
Gender:
<input type="radio" name="gender" value="M" checked="checked" />Male
<input type="radio" name="gender" value="F" />Female
</p><p>
Email address: <input type="text" name="email" size="30" />
</p><p>
Password: <input type="password" name="pword" />
</p><p>
What are your favorite computer classes?
<br />
<label>
<input type="checkbox" name="class-int" />Internet Development
</label>
<label>
<input type="checkbox" name="class-net" />Networking
</label>
<label>
<input type="checkbox" name="class-gui" />GUI
</label>
<label>
<input type="checkbox" name="class-oop" />OOP
</label>
</p><p>
Are you graduating this spring?
<label>
<input type="radio" name="grad-yes" value="Yes" />Yes
</label>
<label>
<input type="radio" name="grad-no" value="Yes" />No
</label>
</p><p>
<input type="submit" value="Submit Survey" />
<input type="reset" value="Clear Form" />
</p>
</form>
<p>
Thank You!
</p>
</body>
</html>
These two elements should probably have the same name:
<input type="radio" name="grad-yes" value="Yes" />
<input type="radio" name="grad-no" value="Yes" />
Radio buttons get grouped together if and only if they share a common name.
The first pair is called gender, so it works.
The second pair doesn't, since one is called grad-yes and the other grad-no.
The way to go would be:
<label>
<input type="radio" name="grad" value="Yes" />Yes
</label>
<label>
<input type="radio" name="grad" value="No" />No
</label>