how to style a button after clicking another button? - html

I am trying to change button 2 to finger pointer after clicking button 1
so i am wondering is there a way to do it if there is please tell me what code do i write
Note:button 1 is already a finger pointer i want button 2 to be a finger pointer after clicking button 1
this is my code:
<input type="button" id="button1" type="submit" style="cursor: pointer; background-color:black;height: 45px; width: 150px; color:red;border-radius:10px;"value="first button" onclick="enableButton2()" />
<input type="button" id="button2" style="background-color:yellow; height: 45px;width: 225px;color:red;border-radius:10px;"value="second button" disabled />

use it :
<script>
function enableButton2(){
var btn2 = document.getElementById('button2');
btn2.setAttribute('disabled', false)
btn2.style.cursor = 'pointer'
}
</script>
<input type="button" id="button1" type="submit" style="cursor: pointer; background-color:black;height: 45px; width: 150px; color:red;border-radius:10px;" value="first button" onclick="enableButton2()" />
<input type="button" id="button2" style="background-color:yellow; height: 45px;width: 225px;color:red;border-radius:10px;" value="second button" disabled="true" />

this way:
the css style you are looking for is cursor : not-allowed;
const bt_1 = document.getElementById('button1')
, bt_2 = document.getElementById('button2')
;
bt_1.onclick = () =>
{
bt_2.disabled = false
}
button {
cursor : pointer;
height : 45px;
border-radius : 10px;
color : red;
}
button[disabled] {
cursor : not-allowed;
pointer-events : none;
color : #c0c0c0;
background-color : #ffffff !important;
}
#button1 {
background-color : black;
width : 150px;
}
#button2 {
background-color : yellow;
width : 225px;
}
<button id="button1" type="submit" > first button </button>
<button id="button2" disabled > second button </button>

Related

Button changing color after closing modal

I am working on a site, and i have a modal which basically looks like this:
import React,{useState} from "react";
import './AddItem.css';
import { Form, Button,Modal } from "react-bootstrap";
function AddItem({open, setOpen})
{
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
return(
<>
<Button className="add" onClick={handleShow}>
ADD
</Button>
<Modal show={show} onHide={handleClose}>
<Modal.Header closeButton>
<Modal.Title>Modal heading</Modal.Title>
</Modal.Header>
<Modal.Body>
<Form>
<Form.Group className="mb-3" controlId="exampleForm.ControlInput1">
<Form.Label>Email address</Form.Label>
<Form.Control
type="email"
placeholder="name#example.com"
autoFocus
/>
</Form.Group>
<Form.Group
className="mb-3"
controlId="exampleForm.ControlTextarea1"
>
<Form.Label>Example textarea</Form.Label>
<Form.Control as="textarea" rows={3} />
</Form.Group>
</Form>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
<Button variant="primary" onClick={handleClose}>
Save Changes
</Button>
</Modal.Footer>
</Modal>
</>
);
}
export default AddItem;
When i click on save changes, or close the modal in any way, the add button in the picture,(which i clicked to open the modal) turns un undesirable color-
The color only reverts back to normal when i click anywhere else on the screen.
How do i prevent this from occuring? My Additem.css file:
.add{
position: absolute;
top: 21.35%;
left: 61%;
height: 6%;
width: 10%;
color: white;
background-color: #283d4a;
border-left: 1.5px solid #15aef1;
border-right: 1.5px solid #15aef1;
border-top: 2.7px solid #15aef1;
border-bottom: 2.7px solid #15aef1;
border-top-left-radius: 5px !important;
border-bottom-left-radius: 5px !important;
}
.add:hover{
background-color:#15aef1 ;
}
The color problem lies with bootstrap button. It has a property of rolling back to a color. Using a regular button like:
#React Button
<button className="add" onClick={handleShow}>
ADD
</button>
instead of
#Bootstrap button
<Button className="add" onClick={handleShow}>
ADD
</Button>
is effective in solving this.

Changing button background color when a certain condition has been met

I want the button to change its background color only when the input text length is 10, when I hover over it.
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cafteria details</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h2>Cafeteria registration</h2>
<form class="details">
Organization:<div id="org"><input type="checkbox" id="cb1" >ID no: <input type="number" id="org_number" style="visibility: hidden"><br><br>
<input type="checkbox" id="cb2" >Mobile No: <input type="tel" id="ph_number" style="visibility: hidden" required></div><br><br>
</form>
<button id="button" onmouseover="hovar()">Register</button>
<script src="back_end.js" async></script>
</body>
</html>
css:
#button{
font-size:20px;
margin-left: 600px;
border-radius: 8px;
}
#button:hover{
background-color: lightsalmon;
color: aquamarine;
}
javascript:
function hovar(){
var phone=document.getElementById("ph_number").value;
var btn=document.getElementById("button");
if (phone.length!=10){
btn.onmouseover.style.backgroundColor="lightsalmon"
}
else{
btn.onmouseover.style.backgroundColor="chartreuse"
btn.onmouseover.style.color="black"
}
}
But I keep getting this error in the javascript:
**Uncaught TypeError: Cannot set property 'backgroundColor' of undefined**
What am I doing wrong here?
you want to apply a "style" property to an event (onmouseover)
function hovar()
{
var phone = document.getElementById("ph_number").value;
var btn = document.getElementById("button");
if (phone.length!=10)
{
btn.style.backgroundColor="lightsalmon" // remove onmouseover
}
else
{
btn.style.backgroundColor="chartreuse"
btn.style.color="black"
}
}
I think this is what you are looking for (?):
const phone = document.getElementById("ph_number")
, btn = document.getElementById("button")
;
phone.oninput = () =>
{
if (phone.value.length != 10)
{
btn.style.setProperty('--hoverBG', 'lightsalmon')
btn.style.setProperty('--hoberColor', 'aquamarine')
}
else
{
btn.style.setProperty('--hoverBG', 'chartreuse')
btn.style.setProperty('--hoberColor', 'black')
}
}
#button {
--hoverBG : lightsalmon;
--hoberColor : aquamarine;
font-size : 20px;
margin-left : 50px;
border-radius : 8px;
}
#button:hover{
background-color : var(--hoverBG);
color : var(--hoberColor);
}
input[type="checkbox"] + label + input {
visibility: hidden;
}
input[type="checkbox"]:checked + label + input {
visibility: visible;
}
<h2>Cafeteria registration</h2>
<form class="details">
Organization:
<div id="org">
<input type="checkbox" id="cb1">
<label for="cb1">ID no : </label>
<input type="number" id="org_number" >
<br><br>
<input type="checkbox" id="cb2">
<label for="cb2">Mobile No: </label>
<input type="tel" id="ph_number" placeholder="phone 10c">
</div>
<br><br>
</form>
<button id="button">Register</button>

Button does not get hidden on hover

I would hide a buttons except the last one . But when I put mouse over prevous elements, they get displayed.
Here's my html
<p-growl [(value)]="msgs"></p-growl>
<div class="center" appMcard>
<h2> Select Group (s) name(s) </h2>
<form [formGroup]="GroupRMPM_FG" class="form">
<div formArrayName="GroupId_Name" *ngFor="let control of GroupRMPM_FG.controls.GroupId_Name.controls; let i= index" >
<input type="text" pInputText [formControl]="control.controls.Group_Id_Name"/>
<button pButton type="button" class="delete-btn " *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length > 1" (click)="deleteGroup(i)" icon="fa-minus" >
</button>
<button *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length == i+1" pButton type="button" (click)="addNewGroup()" icon="fa-plus" class="add-btn formcontainer"></button>
<button *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length != i+1" pButton type="button" class="dummyElement" icon="fa-plus" ></button>
<button *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length == 1" pButton type="button" class="dummyElement" icon="fa-plus" ></button>
</div>
</form>
<div>
I have created a "dummy element" so that the content is centred in the right way when I get only a "plus" icon .
Here's the CSS:
.dummyElement, .dummyElement:hover{
background-color:transparent;
border-color: transparent;
cursor:none;
color: transparent;
}
Here's what I get
Also the cursor is disappearing when I'm over the button.
In my Browser dev tool show me this :
For information I use primeNg Button.
Please use pointer-events: none; instead of cursor:none as below;
.dummyElement, .dummyElement:hover{
background-color:transparent;
border-color: transparent;
pointer-events: none;
color: transparent !important;
}
It seems like your CSS is overwritten by another CSS rule. Try to add !important to your CSS:
.dummyElement, .dummyElement:hover{
background-color:transparent;
border-color: transparent;
cursor:none;
color: transparent !important;
}

Checkbox in codeigniter

Here i am using Bootstrap for checkbox ... While i am click checkbox it checked but in the bootstrap design it was not shown ...
my Code:
<label for="success" class="btn btn-success">Success <input type="checkbox" value="" id="success" class="badgebox"><span class="badge">&check;</span></label>
My css code:
<style>
/* Hiding the checkbox, but allowing it to be focused */
.badgebox
{
opacity: 0;
}
.badgebox + .badge
{
/* Move the check mark away when unchecked */
text-indent: -999999px;
/* Makes the badge's width stay the same checked and unchecked */
width: 27px;
}
.badgebox:focus + .badge
{
/* Set something to make the badge looks focused */
/* This really depends on the application, in my case it was: */
/* Adding a light border */
box-shadow: inset 0px 0px 5px;
/* Taking the difference out of the padding */
}
.badgebox:checked + .badge
{
/* Move the check mark back when checked */
text-indent: 0;
}</style>
Controller
public function workout()
{
if($this->input->post())
{
echo "<pre>"; print_r($this->input->post());
exit();
}
$this->load->view('workout');
}
view file
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<style type="text/css">
.sr-only {
opacity: 0;
float: right;
}
input[type='checkbox'].tags-checkbox:checked + label > i:first-of-type,
input[type='checkbox'].tags-checkbox + label > i:last-of-type{
display: none;
}
input[type='checkbox'].tags-checkbox:checked + label > i:last-of-type{
display: inline-block;
}
</style>
<form name="form" id="form" action="<?php echo base_url(); ?>welcome/workout" method="post" >
Vehicles you have.?
<br /><br />
<div><span class='label-content'> I have a car</span>
<input name="optionshaving[]" type='checkbox' id='checkbox-1' value="bike" class='tags-checkbox sr-only'/>
<label for='checkbox-1'>
<i >✗</i>
<i >&check;</i>
</label>
</div>
<div><span class='label-content'> I have a bike</span>
<input name="optionshaving[]" type='checkbox' value="car" id='checkbox-2' class='tags-checkbox sr-only'/>
<label for='checkbox-2'>
<i >✗</i>
<i >&check;</i>
</label>
</div>
<input type="submit" name="submit" id="submit" value="submit" />
</form>
</body>
</html>
output is
Array
(
[optionshaving] => Array
(
[0] => bike
[1] => car
)
[submit] => submit
)

Click outside button to close popup using toggle

I used toggle to make a search form from a button. But I want click outside any position to close search form, not only using button.
HTML
Search
<div class="search_field" style="display:none;">
<form>
<input name="search" class="search" value="" placeholder="Search Item...." type="text" data-theme="e" />
<input type="submit" value="Search" data-mini="false" data-icon="search" data-iconpos="notext" data-theme="c" />
</form>
</div>
Jquery :
$(function() {
$(".opensearch").on('click', tapHandler);
function tapHandler(event) {
$('.search_field').toggle();
$('.search').focus();
}
});
Demo of JsFiddle
Many thanks for your help.
Use the blur event:
$(".search").on("blur",function(){
$('.search_field').toggle();
});
Updated fiddle: JsFiddle demo
[Edit] You might want to check if the new focus is not on the search icon before hiding the field:
$(".search").on("blur",function(){
setTimeout(function(){
var target = document.activeElement;
target = target ? target.id||target.tagName||target : '';
if(target!="INPUT"){
$('.search_field').toggle();
}
}, 1);
});
Better with the id of the button though....
Example: JsFiddle demo
You can do something like
$(function() {
$(".opensearch").on('click', tapHandler);
//add a click handler to the document object
$(document).on('click', function(e) {
//if the click is happening inside the search_field or opensearch elements then don't do anything
if ($(e.target).closest('.search_field, .opensearch').length == 0) {
$('.search_field').hide();
}
});
function tapHandler(event) {
$('.search_field').toggle();
$('.search').focus();
}
});
.search_field {
padding: 10px 10px 0;
position: relative;
}
.search_field .ui-submit {
bottom: -2px;
position: absolute;
right: 18px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Search
<div class="search_field" style="display:none;">
<form>
<input name="search" class="search" value="" placeholder="Search Item...." type="text" data-theme="e" />
<input type="submit" value="Search" data-mini="false" data-icon="search" data-iconpos="notext" data-theme="c" />
</form>
</div>