How to align the checkbox/radio button elements? - html

I am creating a survey form just for a project on FCC.
I tried putting the <input> tag inside <label>, also used <fieldset> but nothing worked.
<p id="purpose">
<label for="business"><input id="business" type="radio" name="purpose" value="business" checked> business</label>
<label for="leisure"><input type="radio" id="leisure" name="purpose" value="leisure">Leisure</label>
<label for="passingby"><input type="radio" id="passingby" name="purpose" value="passingby">Passing by</label>
<label for="others"><input type="radio" id="others" name="purpose" value="others">others</label>
</p>
<p class="improve">What do we need to improve?</p>
<label for="food"><input type="checkbox" id="food" name="food">Food</label>
<label for="rooms"><input type="checkbox" id="rooms" name="rooms">Rooms</label>
<label for="service"><input type="checkbox" id="service" name="service">Service</label>
<label for="none"><input type="checkbox" id="none" name="none">None</label>

Try out this
<form action="">
<input type="radio" name="purpose" value="business"> business<br>
<input type="radio" name="purpose" value="leisure"> leisure<br>
<input type="radio" name="purpose" value="passingby"> passingby<br>
<input type="radio" name="purpose" value="others"> others<br>
</form>
<p class="improve">What do we need to improve?</p>
<label for="food"><input type="checkbox" id="food" name="food">Food</label> <br>
<label for="rooms"><input type="checkbox" id="rooms" name="rooms">Rooms</label><br>
<label for="service"><input type="checkbox" id="service" name="service">Service</label><br>
<label for="none"><input type="checkbox" id="none" name="none">None</label><br>

Label should be sibling of input
<p id="purpose">
<input id="business" type="radio" name="purpose" value="business" checked><label for="business"> business</label>
<input type="radio" id="leisure" name="purpose" value="leisure"><label for="leisure">Leisure</label>
<input type="radio" id="passingby" name="purpose" value="passingby"><label for="passingby">Passing by</label>
<input type="radio" id="others" name="purpose" value="others"><label for="others">others</label>
</p>
<p class="improve">What do we need to improve?</p>

Related

Form validation, I need to limit a form to only submit if every option is checked off. For eksample the birthdate can't be higher than 1989.01.01

The form should not be able to submit the form unless it is filled out. And an error message should pop up.
My problem is that I can't find out how to do this with HTML, because I am not allowed to use JavaScript in this task.
My code:
<form action="https://folk.ntnu.no/anderobs/webtek/receive_form.php" method="post">
<label for="name">Real Name: </label>
<input type="text" id="name" name="name" value=""> <br>
<label for="gender">Your gender: </label>
<input type="radio" id="gender" name="gender" value="Male">
<label for="gender">Male</label>
<input type="radio" id="gender" name="gender" value="Female">
<label for="gender">Female</label> <br>
<label for="email">E-Mail: </label>
<input type="email" id="email" name="email" value=""> <br>
<label for="birthdate">Birthdate: </label>
<input type="date" id="birthdate" name="birthdate" value=""> <br>
<label for="hero">Hero name: </label>
<input type="text" id="hero" name="hero" value=""> <br>
<label for="spandex">Do you wear spandex? </label>
<input type="radio" id="spandex" name="spandex" value="">
<label for="spandex">True</label>
<input type="radio" id="spandex" name="spandex" value="">
<label for="spandex">False</label> <br>
<label for="strengt">Strengt (between 1 and 10): </label>
<input type="number" id="strengt" name="strengt" min="1" max="10"> <br>
<label for="speed">Speed (between 1 and 10): </label>
<input type="number" id="speed" name="speed" min="1" max="10"> <br>
<label for="intelligence">Intelligence (between 1 and 10): </label>
<input type="number" id="intelligence" name="intelligence" min="1" max="10"> <br>
<label for="income">Income: </label>
<input type="number" id="income" name="income" min="0"> <br>
<label for="wealth">Wealth: </label>
<input type="number" id="wealth" name="wealth" min="0"> <br>
<br>
<input type="submit" value="Submit tax form">

How do I align multiple check boxes with their own texts on the same row?

I made a form with some check boxes and the check boxes with their texts are displayed inline:
enter image description here
What I'm trying to do is to display one checkbox with it's text per row so I tried creating a class for all the check boxes and within the CSS, added display: block:
.checkbox {
display: block;
}
From what I've read, it's better to avoid using br tags all the time in your HTML and attempt to do your styling as much as you can within your CSS.
However, this is what happens:
enter image description here
When trying to search online for this issue, I just get results on how to align multiple check boxes/ fields into the same row.
Here is the HTML:
<p>What would you like to see improved? (Check all that apply)</p>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="frontEnd" value="frontEnd">Front-end Projects</input>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="backEnd" value="backEnd">Back-end Projects</input>
<input type="checkbox" class="checkbox" id="dataVisualization" value="frontEnd">Data Visualization</input>
<input type="checkbox" class="checkbox" id="challengesImproved" value="challengesImproved">Challenges</input>
<input type="checkbox" class="checkbox" id="openSourceCommunity" value="openSourceCommunity">Open Source Community</input>
<input type="checkbox" class="checkbox" id="gitterHelpRooms" value="gitterHelpRooms">Gitter help rooms</input>
<input type="checkbox" class="checkbox" id="videos" value="videos">Videos</input>
<input type="checkbox" class="checkbox" id="cityMeetups" value="cityMeetups">City Meetups</input>
<input type="checkbox" class="checkbox" id="wiki" value="wiki">Wiki</input>
<input type="checkbox" class="checkbox" id="forum" value="forum">Forum</input>
<input type="checkbox" class="checkbox" id="additionalCourses" value="additionalCourses">Additional Courses</input>
Something like this could work, but there other ways
label {
display: block;
}
<label>
<input type="checkbox" name="" id="">
Ola3
</label>
<label>
<input type="checkbox" name="" id="">
Ola1
</label>
<label>
<input type="checkbox" name="" id="">
Ola2
</label>
Put your <input type="checkbox"> and <label> for that checkbox in a <div>.
<div>
<input type="checkbox" id="first">
<label for="first">First</label>
</div>
<div>
<input type="checkbox" id="second">
<label for="second">Second</label>
</div>
This way you don't need to style you container because <div> has display: block by default.
Edit: mistake on my end pointed out in comments. Added id to inputs.
Method -1 - using a display:block;
label {display:block;}
<p>What would you like to see improved? (Check all that apply)</p>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="frontEnd" value="frontEnd">Front-end Projects</input>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="backEnd" value="backEnd">Back-end Projects</input>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="dataVisualization" value="frontEnd">Data Visualization</input>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="challengesImproved" value="challengesImproved">Challenges</input>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="openSourceCommunity" value="openSourceCommunity">Open Source Community</input>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="gitterHelpRooms" value="gitterHelpRooms">Gitter help rooms</input>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="videos" value="videos">Videos</input>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="cityMeetups" value="cityMeetups">City Meetups</input>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="wiki" value="wiki">Wiki</input>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="forum" value="forum">Forum</input>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="additionalCourses" value="additionalCourses">Additional Courses</input>
Method -2 : using a <br>
<p>What would you like to see improved? (Check all that apply)</p>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="frontEnd" value="frontEnd">Front-end Projects</input>
<br>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="backEnd" value="backEnd">Back-end Projects</input>
<br>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="dataVisualization" value="frontEnd">Data Visualization</input>
<br>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="challengesImproved" value="challengesImproved">Challenges</input>
<br>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="openSourceCommunity" value="openSourceCommunity">Open Source Community</input>
<br>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="gitterHelpRooms" value="gitterHelpRooms">Gitter help rooms</input>
<br>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="videos" value="videos">Videos</input>
<br>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="cityMeetups" value="cityMeetups">City Meetups</input>
<br>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="wiki" value="wiki">Wiki</input>
<br>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="forum" value="forum">Forum</input>
<br>
<label for="frontEnd">
<input type="checkbox" class="checkbox" id="additionalCourses" value="additionalCourses">Additional Courses</input>

css responsive with checkbox

I got a problem with checkbox and label. When I re-size screen the label split line, and checkbox should split follow label also.currently, when label stay in new line, but checkbox not stay in the same place of label. What I need is pair new line when responsive.
Anyone have any idea? Thanks in advance for your helping!
Below is my code
<div id="score">
<input type="radio" id="score_0" name="score" required="required" value="1">
<label for="score_0" class="required">E</label>
<input type="radio" id="score_1" name="score" required="required" value="2">
<label for="score_1" class="required">D</label>
<input type="radio" id="score_2" name="score" required="required" value="3">
<label for="score_2" class="required">C</label>
<input type="radio" id="score_3" name="score" required="required" value="4">
<label for="score_3" class="required">B</label>
<input type="radio" id="score_4" name="score" required="required" value="5">
<label for="score_4" class="required">B+</label>
<input type="radio" id="score_5" name="score" required="required" value="6">
<label for="score_5" class="required">A</label>
<input type="radio" id="score_6" name="score" required="required" value="7">
<label for="score_6" class="required">S</label>
</div>
You can actually nest your inputs into the label tag, then set a style for the label
.scores label {
white-space: nowrap;
}
<div class="scores">
<label for="score_1" class="required">
<input type="radio" id="score_1" name="score" required="required" value="2">D</label>
<label for="score_2" class="required">
<input type="radio" id="score_2" name="score" required="required" value="3">C</label>
<label for="score_3" class="required">
<input type="radio" id="score_3" name="score" required="required" value="4">B</label>
<label for="score_4" class="required">
<input type="radio" id="score_4" name="score" required="required" value="5">B+</label>
<label for="score_5" class="required">
<input type="radio" id="score_5" name="score" required="required" value="6">A</label>
<label for="score_6" class="required">
<input type="radio" id="score_6" name="score" required="required" value="7">S</label>
</div>
Demo - Easier to resize here

How to align label and radio button?

When you read this... I probably still haven't solved my issue,
I'm trying to align the label and radiobutton, I have tried alot of "Solutions", but nothing works. I have no css on the radio buttons that i created myself.
Output: http://prntscr.com/5am898
My Code:
<div class="row">
<div class="col-md-12">
<div class="btnRadio">
<label class="radio-inline" for="gal2015lbl">
<input name="galTab" id="gal2015" value="2015" type="radio">2015
</label>
<label class="radio-inline" for="gal2014lbl">
<input name="galTab" id="gal2014" value="2014" type="radio">2014
</label>
<label class="radio-inline" for="gal2013lbl">
<input name="galTab" id="gal2013" value="2013" type="radio">2013
</label>
<label class="radio-inline" for="gal2012lbl">
<input name="galTab" id="gal2012" value="2012" type="radio">2012
</label>
<label class="radio-inline" for="galOtherlbl">
<input name="galTab" id="galOther" value="Anders" type="radio">And
</label>
</div>
</div>
</div>
Try placing the input outside the label.
<label class="radio-inline" for="galOtherlbl">
And
</label>
<input name="galTab" id="galOther" value="Anders" type="radio">
put the label in label tag like
<label class="radio inline control-label">Some label</label>
try
FIDDLE DEMO
<div class="row">
<div class="col-md-12">
<div class="btnRadio">
<input name="galTab" id="gal2015" value="2015" type="radio">
<label class="radio-inline" for="gal2015lbl">2015</label>
<input name="galTab" id="gal2014" value="2014" type="radio">
<label class="radio-inline" for="gal2014lbl">2014</label>
<input name="galTab" id="gal2013" value="2013" type="radio">
<label class="radio-inline" for="gal2013lbl">2013</label>
<input name="galTab" id="gal2012" value="2012" type="radio" />
<label class="radio-inline" for="gal2012lbl">2012</label>
<input name="galTab" id="galOther" value="Anders" type="radio"/>
<label class="radio-inline" for="galOtherlbl">And</label>
</div>
</div>
</div>

Posting results of html form on the same page

I have the following form code in the nav bar:
<form id="form">
<p>
<label for="textarea"></label>
<textarea name="textarea" id="textarea" cols="100" rows="5">
Post here
</textarea>
<input id="button" type="submit" value="Submit!" name="submit" onclick = "get('textfield')"/>
</p>
<p>
<input type="radio" name="radio" id="radio-1" />
<label for="radio-1">Section 1</label>
<input type="radio" name="radio" id="radio-2" />
<label for="radio-2">Section 2</label>
<input type="radio" name="radio" id="radio-3" />
<label for="radio-3">Section 3</label>
<input type="radio" name="radio" id="radio-4" />
<label for="radio-4">Section 4</label>
<input type="radio" name="radio" id="radio-5" />
<label for="radio-5">Section 5</label>
<input type="radio" name="radio" id="radio-6" />
<label for="radio-6">Section 6</label>
</p>
</form>
And in the main body within the webpage,I have 6 sections. What I am trying to achieve is if I select one of the radio buttons, write something in the text area and click submit, it should appear within the selected section. So If write hello world and mark section 5, hello world should appear under section 5.
Is there any naive way of achieving this purely in HTML5? If there isn't, can anyone point to any tutorials/links or offer any suggestions?
Thanks in advance!
try to use this Example
<p>
<label for="textarea"></label>
<textarea name="textarea" id="textarea" cols="100" rows="5"></textarea>
<input id="button" type="submit" value="Submit!" name="submit"
</p>
<p>
<input type="radio" name="radio" id="radio-1" />
<label for="radio-1">Section 1</label>
<input type="radio" name="radio" id="radio-2" />
<label for="radio-2">Section 2</label>
<input type="radio" name="radio" id="radio-3" />
<label for="radio-3">Section 3</label>
<input type="radio" name="radio" id="radio-4" />
<label for="radio-4">Section 4</label>
<input type="radio" name="radio" id="radio-5" />
<label for="radio-5">Section 5</label>
<input type="radio" name="radio" id="radio-6" />
<label for="radio-6">Section 6</label>
</p>
<ul>
<li><section id="radio-1"></section></li>
<li><section id="radio-2"></section></li>
<li><section id="radio-3"></section></li>
<li><section id="radio-4"></section></li>
<li><section id="radio-5"></section></li>
<li><section id="radio-6"></section></li>
</ul
JS
$(function () {
$("#button").click(function(){
var txt = $("#textarea").val();
if(txt.length > 0)
{
var id = $("input[type='radio']:checked").attr("id");
$("li section").text("");
$("li #"+id).text(txt);
}
});
});
for solve this you better use simplejavascript code in your form that do this operation with id of radio buttons