Checkbox values fail if not selected? - css

I'm building this checkbox that it woyld only work if all 3 checkboxes are checked on the web. Otherwise it will fail.
I tried to set without value - but it doesn't work at all.
I tried to give them the same value as the name or field - doesn't work.
Works only if the value is set as true - but for some reason it expects it all to be true?
<fieldset class="question-fieldset twocolinputs">
<h2>Question #81:</h2>
<div class="answer-single">
<input id="2-a" name="MX3A" type="checkbox" class="checkbox-button-input" value="true">
<label class="answer-label" for="2-a">
Email
</label>
</div>
<div class="answer-single">
<input id="2-b" name="MX3B" type="checkbox" class="checkbox-button-input" value="true">
<label class="answer-label" for="2-b">
SMS
</label>
</div>
<div class="answer-single">
<input id="2-c" name="MX3C" type="checkbox" class="checkbox-button-input" value="true">
<label class="answer-label" for="2-c">
Llamada
</label>
</div>
</fieldset>

In an <input> of type checkbox, you set the checked property to true, not the value:
<input id="2-b" name="MX3B" type="checkbox" class="checkbox-button-input" checked="true">
▲

Update
Demo 2 is an example of radio button pairs with the value of true and false strings submitted to server.
It seems that everyone is assuming that you want the checkboxes checked by default. Although I could be mistaken, I don't interpret it that way. What I gather is that you only get a value submitted if all of your checkboxes are checked which is odd. As a test I have placed your unmodified code inside a <form> and added a <input type='submit'> button, then posted the <form> to a test server. It will only send the values of the checkboxes that are checked as expected.
Demo 1 - PLUNKER
Demo 1 - STACK (Does not function due to SO security measures, see PLUNKER for a functioning example)
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form id='main' method='post' action='http://httpbin.org/post'>
<fieldset class="question-fieldset twocolinputs">
<h2>
Question #81:
</h2>
<div class="answer-single">
<input id="2-a" name="MX3A" type="checkbox" class="checkbox-button-input" value="true">
<label class="answer-label" for="2-a">
Email
</label>
</div>
<div class="answer-single">
<input id="2-b" name="MX3B" type="checkbox" class="checkbox-button-input" value="true">
<label class="answer-label" for="2-b">
SMS
</label>
</div>
<div class="answer-single">
<input id="2-c" name="MX3C" type="checkbox" class="checkbox-button-input" value="true">
<label class="answer-label" for="2-c">
Llamada
</label>
<input type='submit'>
</div>
</fieldset>
</form>
</body>
</html>
Demo 2 - PLUNKER
Demo 2 - STACK (See PLUNKER for working example)
<!DOCTYPE html>
<html>
<head>
<style>
input,
label {
font: inherit;
}
[type=submit] {
float: right;
}
</style>
</head>
<body>
<form id='main' method='post' action='http://httpbin.org/post'>
<fieldset>
<legend>Question #82</legend>
<p>Using radio buttons that share the same name attribute ensures that only one of them can be checked</p>
<label>True
<input type='radio' name='Q82' value='true'>
</label>
<label>False
<input type='radio' name='Q82' value='false'>
</label>
</fieldset>
<fieldset>
<legend>Question #83</legend>
<p>If you wish to set a default, use the checked attribute. ex. checked='false' (see the radio buttons below)</p>
<label>True
<input type='radio' name='Q83' value='true'>
</label>
<label>False
<input type='radio' name='Q83' value='false' checked='true'>
</label>
</fieldset>
<input type='submit'>
</form>
</body>
</html>

<input id="2-a" name="MX3A" type="checkbox" class="checkbox-button-input" checked>

Related

Making break line without using <br/>

I want to display the first input[email] and my button in one line and make the rest in another line, Also want to disable default style for my checkbox and display it with transparent background.
<form method="post" name="form_BE_box" action="">
<input type="email" name="mail" placeholder="Votre adresse mail" id="MAIL"/>
<button class="button" type="submit">S'inscrire</button><br/>
<input type="checkbox" checked="checked" value="Partenaire" name="fou" /> Cochez ici pour s'inscrire aux communications partenaire
</form>
You can include your input into a div. Here is a working jsfiddle.
And regarding the checkbox you can take a look at this answer: stackoverflow
<form method="post" name="form_BE_box" action="">
<input type="email" name="mail" placeholder="Votre adresse mail" id="MAIL"/>
<button class="button" type="submit">S'inscrire</button>
<div>
<input type="checkbox" checked="checked" value="Partenaire" name="fou" /> Cochez ici pour s'inscrire aux communications partenaire
</div>
</form>

jqueryMobile panel theme not working

I cannot figure out for the life of my why this jquery mobile panel won't render with the same look and feel of the jquery mobile theme used in the application.
The panel is loading on the same page as the rest of my jquery mobile page so the jquery mobile css files and jquery js files are all referenced and working on other parts of the page.
What am I missing within my layout?
thanks
<div data-role="page" id="map_page">
<div data-role="panel" id="transitLayersPage" data-position="right" data-display="overlay">
<div data-role="header">
<h1>Routes</h1>
</div>
<div data-role="controlgroup">
<div id="checkboxes">
<input type="checkbox" id="transitRoutesLayerKML0" onclick="toggleLayer(0)" />
<label>Routes 1</label>
<input type="checkbox" id="transitRoutesLayerKML1" onclick="toggleLayer(1)" />
<label>Routes 2</label>
<input type="checkbox" id="transitRoutesLayerKML0" onclick="toggleLayer(2)" />
<label>Routes 3</label>
<input type="checkbox" id="transitRoutesLayerKML1" onclick="toggleLayer(3)" />
<label>Routes 4</label>
<input type="checkbox" id="transitRoutesLayerKML0" onclick="toggleLayer(4)" />
<label>Routes 5</label>
<input type="checkbox" id="transitRoutesLayerKML1" onclick="toggleLayer(5)" />
<label>Routes 6a</label>
<input type="checkbox" id="transitRoutesLayerKML0" onclick="toggleLayer(6)" />
<label>Routes 6b</label>
</div>
Close panel
</div>
</div>
You forgot to add for attribute to label. Moreover, you should not use duplicate id for checkbox, each checkbox must have a unique id.
<input type="checkbox" id="foo">
<label for="foo">bar</label>
Demo

Twitter Bootstrap - changing height of checkboxes in form

I have a simple HTML form that uses the Twitter Bootstrap framework (v3.1.1). On the smartphone/iPhone these checkboxes are quite small and hard to select with your finger. I would like to make them larger/more spaced out so they are easier to hit but haven't found a way so far - is this even possible.
Here's my form html:
<div class="container">
<div>
<p>Tick all that apply:</p>
<form role="form" action="continue.php" method="post">
<input type="hidden" name="selectionID" value="4567">
<div class="checkbox">
<label>
<input type="checkbox" name="selection[]" value="Fever/Temperature">Apples<br>
<input type="checkbox" name="selection[]" value="Swelling or redness at injection site">Oranges<br>
<input type="checkbox" name="selection[]" value="Pain at injection site">Bananas<br>
<input type="checkbox" name="selection[]" value="Tired/Fatigued">Pears<br>
<input type="checkbox" name="selection[]" value="Irritable">Mangoes<br>
<input type="checkbox" name="selection[]" value="Sleep pattern change">Watermelon<br>
<input type="checkbox" name="selection[]" value="Other">Other<br>
</label>
</div>
<button type="submit" class="btn btn-primary">Next</button>
</form>
</div>
</div>
I've also setup a jsfiddle here
This isn't easy to do cross-broswer .. check out the study made here: http://www.456bereastreet.com/lab/form_controls/checkboxes/
Also, make sure you're using correct HTML code. You should wrap each of your checkboxes with label, like this:
<div class="checkbox">
<label>
<input type="checkbox" name="selection[]" value="Fever/Temperature" />Apples<br/>
</label>
<label>
<input type="checkbox" name="selection[]" value="Swelling or redness at injection site" />Oranges<br/>
</label>
<label>
<input type="checkbox" name="selection[]" value="Pain at injection site" />Bananas<br/>
</label>
<!-- etc. -->
</div>

Jquery mobile radio button selection

I'm trying to implement a horizontal control group in jquery mobile which has radio buttons inside. I am trying to build the HTML string dynamically from code behind.
These radio buttons are in a for loop .
StringBuilder tileString = new StringBuilder(string.Empty);
foreach (Product product in productsInCart)
{
tileString.Append("<div><legend >Choose shipping type:</legend></div><br />");
tileString.Append("<input type='radio' name='radio-choice-1' id='radio-choice-1' onclick='findPaymentMethod()' value='In Flight' checked='checked' />");
tileString.Append("<label for='radio-choice-1'>In flight</label>");
tileString.Append("<input type='radio' name='radio-choice-1' id='radio-choice-2' value='On Arrival' onclick='findPaymentMethod()' />");
tileString.Append("<label for='radio-choice-2'>On Arrival</label>");
} `
As you can see there is a property on the first radio button.
checked='checked'
But when this is run in a for loop only the last radio element in the for loop gets checked. Can anyone suggest me whats wrong with the code ? Or am i missing something here ?
EDIT: HTML string that gets generated is added .
<div data-role='fieldcontain'>
<fieldset data-role='controlgroup' data-type='horizontal' id='6' data-mini='true'>
<div>
<legend >Choose shipping type:</legend>
</div>
<br />
<input type='radio' name='radio-choice-1' id='radio-choice-16' value='In Flight' checked='checked'/>
<label for='radio-choice-16'>In flight</label>
<input type='radio' name='radio-choice-1' id='radio-choice-26' value='On Arrival' />
<label for='radio-choice-26'>On Arrival</label>
</fieldset>
</div>`
`<div data-role='fieldcontain'>
<fieldset data-role='controlgroup' data-type='horizontal' id='1' data-mini='true'>
<div>
<legend >Choose shipping type:</legend>
</div>
<br />
<input type='radio' name='radio-choice-1' id='radio-choice-11' value='In Flight' checked='checked'/>
<label for='radio-choice-11'>In flight</label>
<input type='radio' name='radio-choice-1' id='radio-choice-21' value='On Arrival' />
<label for='radio-choice-21'>On Arrival</label>
</fieldset>
</div>
Only 1 radio element is getting checked within the fieldset
Here's an image of the desired effect.
Your name attribute (like id one) must be unique.
Working example: http://jsfiddle.net/Gajotres/SBxVc/
<div data-role='fieldcontain'>
<fieldset data-role='controlgroup' data-type='horizontal' id='6' data-mini='true'>
<div>
<legend >Choose shipping type:</legend>
</div>
<br />
<input type='radio' name='radio-choice-16' id='radio-choice-16' value='In Flight' checked='checked'/>
<label for='radio-choice-16'>In flight</label>
<input type='radio' name='radio-choice-26' id='radio-choice-26' value='On Arrival' />
<label for='radio-choice-26'>On Arrival</label>
</fieldset>
</div>
<div data-role='fieldcontain'>
<fieldset data-role='controlgroup' data-type='horizontal' id='1' data-mini='true'>
<div>
<legend >Choose shipping type:</legend>
</div>
<br />
<input type='radio' name='radio-choice-11' id='radio-choice-11' value='In Flight' checked='checked'/>
<label for='radio-choice-11'>In flight</label>
<input type='radio' name='radio-choice-21' id='radio-choice-21' value='On Arrival' />
<label for='radio-choice-21'>On Arrival</label>
</fieldset>
</div>

When label tag should be used over span/dev tags in html form?

When label tag should be used over span or dev in form?
Example:
option1-span:
<form action="">
<span>Name:</span><input type="text">
<input type="submit" />
</form>
option2-label:
<form action="">
<label>Name:</label><input type="text">
<input type="submit" />
</form>
option3-div:
<form action="">
<div style="display:inline;">Name:</div><input type="text">
<input type="submit" />
</form>
Thanks
This is what label tags are for:
<form action="">
<label for="txt">Name:</label><input type="text" id="txt" name="txt" />
<input type="submit" />
</form>
Then clicking on the label will focus on the input element.
The label tag is primarily used along with the for attribute. This aids in web accessibility of forms. For example
<form>
<label for="firstName">First name:</label>
<input type="text" name="firstName" value=""/>
</form>
By using the for tag, we can essentially associate the text "First Name:" with the input field having the name = "firstName".
Aside from that it has other attributes allowed but the span is more regularly used for styling markup.

Resources