How to make a checkbox into a button? - html

Here is the code. There is a search bar where a user can put in a topic then select a button that shows different categories.
<form action="search.php" method="GET">
<i class="fas fa-search" aria-hidden="true"></i>
<input placeholder="Search" name="search" aria-label="Search">
<input type="submit" value="S" class="searchButton" name="submit-request"/>
<div class="buttons" style="text-align:center;">
<input type="button" class="spec" name="category1" value="category1">
<input type="button" class="spec" name="category2" value="category2">
<input type="button" class="spec" name="category3" value="category3">
<input type="button" class="spec" name="category4" value="category4">
<input type="button" class="spec" name="category5" value="category5">
</div>
</form>
This search form works perfectly fine with checkboxes. What should I do as an alternative? Is there a way I can style the checkboxes as buttons. If they are checkboxes how can I make it so that a user can only pick one category.

Use radio buttons.
Show name for radio with label.
To style a radio button, hide it, and add pseudo element.

<button> is it's own tag.
<button class="spec" name="category5">category5</button>
If you wanted to use CSS (you didn't tag it in your post), you can try this:
https://www.w3schools.com/css/tryit.asp?filename=trycss_form_button

<div class="navigation">
<input type="checkbox" class="navigation__checkbox" id="**navi-toggle**">
<label for="**navi-toggle**" class="navigation__button">
<span class="navigation__icon"> </span>
</label>
</div>
.navigation {
&__checkbox {
display: none;
}
&__button{
background-color: $color-white;
height: 7rem;
width: 7rem;
}
You say that you want to be able to still use checkbox as that is what functions... Well you could do so and use a label that is linked to that checkbox, and then simply style your label as your button.

Related

Foundation and modals/reveal

I'm running into issues with modals and forms with Foundation.
I want to be able to fill out a form, open a modal, then have that modal be able to submit the form.
Normally, I'd have my form, and all of it's form fields, and put the modal inside the the form element, and that would be fine - but with foundation, I find that the reveal modal is moved to the bottom of the DOM.
What's the best way to accomplish what I'm after?
I've added a skeleton of what my normal structure might be like - any help would be greatly appreciated.
<form method="post" action="...">
<label for="title">Title</label>
<input type="text" name="title" id="title" placeholder="Enter campaign title here" required>
<label for="title">Description</label>
<textarea type="text" name="description" placeholder="Description of this campaign"></textarea>
<button type="button" class="button default-btn float-right" data-open="emailSendConfirmation">Publish campaign</button>
<div class="reveal" id="emailSendConfirmation" data-reveal>
<button data-close aria-label="Close modal" type="button" class="button">Cancel</button>
<button type="submit" class="button" name="status" value="Published">Publish</button>
</div>
</form>
Thanks,
Ollie

Make button act as span in bootstrap

I have the form below, in which I have a search glyphicon inside the input.
<form method="get">
<div class="input-group">
<input type="text" class="form-control" id="city" name="city"/>
<span class="input-group-addon btn"><span class="glyphicon glyphicon-search"></span></span>
</div>
</form>
I'd like to make my glyphicon submit my form, but for that I'd have to change the span for a input or button. In either way, the glyphicon goes outside the input and displays below it. I couldn't figure out why yet. I was able to put it in the correct position through absolute positioning, but it is not good for the way it is displayed in the website. Is there any way to solve this problem only with css and without absolute positioning?
The problem is bootstrap style buttons and inputs differently. You can use <span> and submit form with onclick event.
See this code:
<form id="myForm" method="get">
<div class="input-group">
<input type="text" class="form-control" id="city" name="city"/>
<span class="input-group-addon btn" onclick="document.getElementById('myForm').submit();" ><span class="glyphicon glyphicon-search"></span></span>
</div>
</form>
Working JSFiddle:
http://jsfiddle.net/q76dasdk/

Bootstrap button group pre-select button with html only

Using Bootstrap I want a button group but with one button preselected. If I use the html below then the first button gets preselected, but it remains active even when I click on one of the other buttons.
Using only html how can I define the button group with one button selected where that button will deselect when I click on one of the other buttons.
<div class="btn-group">
<button type="button" class="btn btn-default active">Left</button>
<button type="button" class="btn btn-default">Middle</button>
<button type="button" class="btn btn-default">Right</button>
</div>
It's not completely possible to do this with HTML only - (as your title implies).
Really, the only thing you could do without JavaScript is add the attribute autofocus="autofocus" to the desired element like this:
<button type="button" class="btn btn-default" autofocus="autofocus">Left</button>
As the attribute implies, the button will automatically be focused in supported browsers. If another button is clicked, the focus of the first button will be removed.
EXAMPLE HERE
It's worth noting that the styling of .btn-default.active is the same as .btn-default:focus:
.btn-default:focus, .btn-default.active {
color: #333;
background-color: #ebebeb;
border-color: #adadad;
}
Unfortunately, the focus will also be removed when clicking anywhere else on the page too. If this is a problem, JavaScript would be needed to solve this. The solution would be to have the active class on the desired element and then remove it when clicking on any of the sibling button elements. The selection would be mutually exclusive like with radio elements.
Here is an example taken directly from the Bootstrap JS documentation. It's worth noting that the Bootstrap JS file/jQuery need to be included.
EXAMPLE HERE
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active">
<input type="radio" name="options" id="option1"> Option 1
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option2"> Option 2
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option3"> Option 3
</label>
</div>

Bootstrap Radio button : radio circle removal

I am trying to use Bootstrap for my website. I have radio buttons and I am trying to use "Buttons" from bootstrap for the same.
<td style="margin-bottom:0px; padding-bottom: 0px;font-size=12px;vertical-align:bottom;">
<div class="btn-group" data-toggle="buttons" id="topButtonDiv" >
<button type="button" class="btn btn-primary">Home
<input type="radio" id="radio1" ></button>
<button type="button" class="btn btn-primary">Home1
<input type="radio" id="radio2" > </button>
<button type="button" class="btn btn-primary">Home2
<input type="radio" id="radio7"> </button>
</div>
</td>
The problem I am facing is that I still see the circles in the Radio button present, where as in the Bootstrap example, I see no such circles present.
http://getbootstrap.com/javascript/#buttons-usage
Can you let me know what I am missing here?
Another alternative if the css version update is not working is to manually hide the radio button using css
[type='radio'] {
display: none;
}
Check for the version of css you've added. The same btn-group class works fine here
Your markup for bootstrap radio buttons is wrong, you make it like this:
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
Option one is this and that—be sure to include why it's great
</label>
</div>
Furthermore you can't put a input element within a button element. That's invalid html.

HTML Display Fieldset and Button inline

I have a fieldset with a text input box, with a submit button. I want them to appear in a single row but the fieldset appears in one row, and then the continue appears in the next. Here's my html:
<label><fieldset class="registration_code">
<legend>Registration Code</legend>
<input type="text" name="regis_code" id="regis_code"/>
</fieldset>
<input type="button" class="button2" name="Submit" value="Continue"/>
</label>
I've tried all combinations of making the button or the fieldset inline, inline-block, float:left, float:right. none of them are resulting in what I want. I just want a single row displaying both of these elements. How do I go about doing this?
Not sure why you wrapped your code in a label tag:
http://jsfiddle.net/hyxaK/1/
<fieldset class="registration_code">
<legend>Registration Code</legend>
<input type="text" name="regis_code" id="regis_code"/>
</fieldset>
<input type="button" class="button2" name="Submit" value="Continue"/>
.registration_code { display:inline-block; }
Either you can do this,
<label>
<fieldset class="registration_code">
<legend>Registration Code</legend>
<input type="text" name="regis_code" id="regis_code"/>
<input type="button" class="button2" name="Submit" value="Continue"/>
</fieldset>
</label>​
or this,
fieldset{
display : inline-block;
}​
DEMO