I want a form where someone choose a unique value of radio buttons vertical and horizontal (you'll see below what i mean). I know tha i can do it with name. In my code below you see same name in vertical.
Here's my code
<tr>
<td style="text-align:left;">tracking_url</td>
<td><input type="radio" name="tracking_url" value="image_url"></td>
<td><input type="radio" name="pr_image" value="tracking_url"></td>
<td><input type="radio" name="availability" value="tracking_url"></td>
<td><input type="radio" name="pr_price" value="tracking_url"></td>
<td><input type="radio" name="pr_final_price" value="tracking_url"></td>
<td></td>
</tr>
<tr>
<td style="text-align:left;">image_url</td>
<td><input type="radio" name="tracking_url" value="image_url"></td>
<td><input type="radio" name="pr_image" value="image_url"></td>
<td><input type="radio" name="availability" value="image_url"></td>
<td><input type="radio" name="pr_price" value="image_url"></td>
<td><input type="radio" name="pr_final_price" value="image_url"></td>
<td></td>
</tr>
<tr>
<td style="text-align:left;">availability</td>
<td><input type="radio" name="tracking_url" value="availability"></td>
<td><input type="radio" name="pr_image" value="availability"></td>
<td><input type="radio" name="availability" value="availability"></td>
<td><input type="radio" name="pr_price" value="availability"></td>
<td><input type="radio" name="pr_final_price" value="availability"></td>
<td></td>
</tr>
<tr>
<td style="text-align:left;">price</td>
<td><input type="radio" name="tracking_url" value="price"></td>
<td><input type="radio" name="pr_image" value="price"></td>
<td><input type="radio" name="availability" value="price"></td>
<td><input type="radio" name="pr_price" value="price"></td>
<td><input type="radio" name="pr_final_price" value="price"></td>
<td></td>
</tr>
<tr>
<td style="text-align:left;">full_price</td>
<td><input type="radio" name="tracking_url" value="full_price"></td>
<td><input type="radio" name="pr_image" value="full_price"></td>
<td><input type="radio" name="availability" value="full_price"></td>
<td><input type="radio" name="pr_price" value="full_price"></td>
<td><input type="radio" name="pr_final_price" value="full_price"></td>
<td></td>
</tr>
This is how i want to use radio buttons
but also someone can use radio buttons like
Is there any way to do it with html or javascript??
var col, el;
$("input[type=radio]").click(function() {
el = $(this);
col = el.data("col");
$("input[data-col=" + col + "]").prop("checked", false);
el.prop("checked", true);
});
table {
border-collapse: collapse;
}
td, th {
border: 1px solid #ccc;
padding: 10px;
}
th:empty {
border: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<table>
<tr>
<th></th>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
<tr>
<td>Twix</td>
<td><input type="radio" name="row-1" data-col="1"></td>
<td><input type="radio" name="row-1" data-col="2"></td>
<td><input type="radio" name="row-1" data-col="3"></td>
</tr>
<tr>
<td>Snickers</td>
<td><input type="radio" name="row-2" data-col="1"></td>
<td><input type="radio" name="row-2" data-col="2"></td>
<td><input type="radio" name="row-2" data-col="3"></td>
</tr>
<tr>
<td>Butterfingers</td>
<td><input type="radio" name="row-3" data-col="1"></td>
<td><input type="radio" name="row-3" data-col="2"></td>
<td><input type="radio" name="row-3" data-col="3"></td>
</tr>
</table>
https://css-tricks.com/radio-buttons-with-2-way-exclusivity/
The radio buttons within a row need to have the same name="nameValue" value. The value fields can be different for each radio button.
I think it would be better to use checkboxes. And control if other checkboxes could be checked or not using javascript.
Here I implemented in Angular 7 input radio button vertically and horizontal
The Idea behind this is that with radio button we have name property which makes single select either by row or column but for both row and column. I placed the row in name and handled column with javascript whenever button will click.
This is HTML CODE
<section class="editor">
<strong>Editor</strong>
<div>
<label>Add option</label>
<button (click)="addOption()">+</button>
<div *ngFor="let option of options;let i = index">
<span>{{option.title +(i+1)}}</span><button (click)="deleteOption(i)"
*ngIf="options.length>2">X</button>
</div>
</div>
</section>
<hr>
<section>
<strong>Builder</strong>
<div class="builder">
<label>Question title goes here</label><br>
<div *ngFor="let option of options;let row_index = index">
<span>{{option.title +(row_index+1)}}</span>
<span *ngFor="let rank of options;let column_index=index">
<input type="radio" name="{{row_index}}" class="{{column_index}}"
(click)="check(column_index,$event)">
</span>
</div>
</div>
</section>
And this is my .ts file code where I Implemented with Javascript
export class AppComponent {
options = [{
title: "option",
rank: 0,
}, {
title: "option",
rank: 0
}]
constructor() {
}
ngOnInit(): void { }
addOption() {
this.options.push({
title: "option",
rank: 0
})
}
deleteOption(i) {
this.options.splice(i, 1);
}
check(column_index, event) {
Array.from(document.getElementsByClassName(column_index)).map(x=>x['checked']=false);
event.target.checked=true;
}
}
Related
I have 2 columns 'Select' & 'Super' these columns have checkboxes, and can be selected or unselected by the user. What I am looking for is a jQuery solution to :
If any checkbox in Column B (super) is selected then the
corresponding checkbox in Column A (select) should be checked
If any checkbox in Column A (select) is unselected, then the
corresponding checkbox in Column B (super) should be unchecked
The HTML code that I have is:
<td>
<input type="checkbox" id="select1" checked="checked" class="select-checkbox">
</td>
<td><input type="checkbox" id="super1" class="super-checkbox">
</td>
</tr>
<tr>
<td><input type="checkbox" id="select2" class="select-checkbox">
</td>
<td><input type="checkbox" id="super2" class="super-checkbox">
</td>
</tr>
<tr>
<td><input type="checkbox" id="select3" checked="checked" class="select-checkbox">
</td>
<td><input type="checkbox" id="super3" checked="checked" class="super-checkbox">
</td>
</tr>
<tr>
<td><input type="checkbox" id="select4" checked="checked" class="select-checkbox">
</td>
<td><input type="checkbox" id="super4" checked="checked" class="super-checkbox">
</td>
</tr>```
First you need to add a common class to all select checkboxes, and a common class to all super checkboxes
$(function(){
$('.super-checkbox').change(function(e){
const chk = $(this);
if(chk.is(':checked')){
//Super is checked
// get the closest tr
const tr = chk.closest('tr');
//find the select checkbox, under this tr
const selectChk = tr.find('.select-checkbox');
//Check this select checkbox
selectChk.prop('checked',true);
}
});
$('.select-checkbox').change(function(e){
const chk = $(this);
if(!chk.is(':checked')){
//Select is not checked
// get the closest tr
const tr = chk.closest('tr');
//find the super checkbox, under this tr
const selectChk = tr.find('.super-checkbox');
//un-Check this select checkbox
selectChk.prop('checked', false);
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td>
<input type="checkbox" id="select1" checked="checked" class="select-checkbox">
</td>
<td><input type="checkbox" id="super1" class="super-checkbox">
</td>
</tr>
<tr>
<td><input type="checkbox" id="select2" class="select-checkbox">
</td>
<td><input type="checkbox" id="super2" class="super-checkbox hrpda-interview-super-checkbox">
</td>
</tr>
<tr>
<td><input type="checkbox" id="select3" checked="checked" class="select-checkbox hrpda-interview-select-checkbox">
</td>
<td><input type="checkbox" id="super3" checked="checked" class="super-checkbox">
</td>
</tr>
<tr>
<td><input type="checkbox" id="select4" checked="checked" class="select-checkbox">
</td>
<td><input type="checkbox" id="super4" checked="checked" class="super-checkbox">
</td>
</tr>
</table>
I've been stuck for hours on a problem that might be actually simple but I can't manage to find the solution.
To be short, I want to know the index (ie the first / the second / the third etc...) of a checkbox when clicking on it.
Here's the jsfiddle showing what's currently working and what is not. I've tried many things but couldn't find the solution I'm looking for.
https://jsfiddle.net/cpydwqk3/2/ <div>(this example applies only for the class "admin" which applies herself on the checkbox "admin").
function usermodif(identifiant) {
alert($('.admin').index(this)); //return -1
}
$("tr").click(function() {
alert($("tr").index(this)); //work but applies on whole line
});
<table>
<caption>Utilisateurs</caption>
<tr>
<th scope="col">pseudo</th>
<th scope="col">points</th>
<th scope="col">points_session</th>
<th scope="col">admin</th>
<th scope="col">banni</th>
</tr>
<tr>
<th scope="row">firstguy</th>
<td><input type="text" name="points" value="45" id="points"></td>
<td><input type="text" name="points_session" value="6" id="points_session"></td>
<td><input type="checkbox" class="admin" name="admin" onclick="usermodif(this.className)"> </td>
<td><input type="checkbox" class="banni" name="banni"> </td>
</tr>
<tr>
<th scope="row">Nico</th>
<td><input type="text" name="points" value="21" id="points"></td>
<td><input type="text" name="points_session" value="21" id="points_session"></td>
<td><input type="checkbox" class="admin" name="admin" onclick="usermodif(this.className)" checked> </td>
<td><input type="checkbox" class="banni" name="banni"> </td>
</tr>
<tr>
<th scope="row">anonyme</th>
<td><input type="text" name="points" value="0" id="points"></td>
<td><input type="text" name="points_session" value="0" id="points_session"></td>
<td><input type="checkbox" class="admin" name="admin" onclick="usermodif(this.className)"> </td>
<td><input type="checkbox" class="banni" name="banni"> </td>
</tr>
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
Thanks in advance guys!
Traverse first tp the closest TR. Than get that closest TR index.
TR has an index amongst TBODY TRs, but not the checkbox.
Also, never use inline JavaScript on* attributes, same as you hopefully don't use inline style attributes. JS and CSS should be in one place only, and that's their respective files or tags.
$(".admin").on("click", function() {
const $par = $(this).closest("tr");
alert($par.index());
});
<table>
<tr>
<th scope="row">firstguy</th>
<td><input type="text" name="points" value="45" id="points"></td>
<td><input type="text" name="points_session" value="6" id="points_session"></td>
<td><input type="checkbox" class="admin" name="admin"> </td>
<td><input type="checkbox" class="banni" name="banni"> </td>
</tr>
<tr>
<th scope="row">firstguy</th>
<td><input type="text" name="points" value="45" id="points"></td>
<td><input type="text" name="points_session" value="6" id="points_session"></td>
<td><input type="checkbox" class="admin" name="admin"> </td>
<td><input type="checkbox" class="banni" name="banni"> </td>
</tr>
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
I have deleted my previous question as it was misleading in what I thought the issue was versus what I now think. I am having issues with blank space during vertical scrolling in mobile viewing. I have tried a handful of things, including messing with the viewport and the css and the only thing that seems to help is removing rows from the table to get it under a certain size. I'm sure there is some way around this, but I just haven't been able to figure it out. It doesn't appear to be an issue with the width of the table, I have tried several things to change that and nothing helped. It seems to be a forced page break due to the length of the form vertically. Here is the HTML:
<!DOCTYPE html>
<html>
<head><meta name="viewport" content="height=device height, width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/></head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/willowsystems/jSignature/master/libs/jSignature.min.js"></script>
<style>
body {
font-family: Arial;
background-color: MidnightBlue;
color: GhostWhite;
display: inline-block;
}
.modal {
width: 100%;
height: 100%;
border: 2px solid #ccc;
border-radius: 4px;
background-color: GhostWhite;
color: Black;
}
input[type=text], select {
width: 100%;
height: 100px;
padding: 12px 20px;
margin: 8px 0;
display: block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 2em;
}
input[type=number], select {
width: 100%;
height: 100px;
padding: 12px 20px;
margin: 8px 0;
display: block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 2em;
}
input[type=date], select {
width: 100%;
height: 100px;
padding: 12px 20px;
margin: 8px 0;
display: block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 2em;
}
input[type=time], select {
width: 100%;
height: 100px;
padding: 12px 20px;
margin: 8px 0;
display: block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 2em;
}
input[type=submit] {
width: 100%;
background-color: DarkRed;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1em;
}
input[type=radio] {
width: 50px;
height: 50px;
}
input[type=button] {
width: 150px;
height: 50px;
font-size: 30px;
display: block;
margin-left: auto;
}
#Address th, #Address td {
border: 2px solid #ddd;
font-size: 60px;
font-weight: bold;
width: 20%;
text-align: center;
}
#Inspection {
table-layout: auto;
height: 100%;
}
#Inspection th, #Inspection td {
border: 2px solid #ddd;
}
#Inspection th {
font-size: 30px;
text-align: left;
}
#Inspection td {
font-size: 15px;
text-align: center;
}
#customerForm {
font-size: 2em;
font-weight: Bold;
}
::placeholder {
font-size: 1em;
}
</style>
<body>
<center><h1><big><big>DRIVER VEHICLE INSPECTION REPORT</big></big></h1>
<h5>AS REQUIRED BY THE D.O.T. FEDERAL MOTOR CARRIER SAFETY REGULATIONS</h5></center><br>
<form id="customerForm" action="/action_page.php">
<div class="container">
<label for="carrier">Carrier:</label>
<select id="carrier" name="carrier" required>
<option value="My Company">My Company</option>
</select><br>
<table id="Address" width="100%">
<tr>Select Your Terminal Location:</tr>
<tr>
<th>PDX</th>
<th>EUG</th>
<th>SEA</th>
<th>SFO</th>
</tr>
<tr>
<td><input type="radio" id="PDX" name="Address" value="PDX"required></td>
<td><input type="radio" id="EUG" name="Address" value="EUG"required></td>
<td><input type="radio" id="SEA" name="Address" value="SEA"required></td>
<td><input type="radio" id="SFO" name="Address" value="SFO"required></td>
</tr>
</table><br>
<label for="Driver name">Driver Performing Inspection:</label>
<input type="text" id="dname" name="drivername" placeholder="Your full name" required><br>
<label for="Driver Employee ID number">Driver's Employee Number:</label><br>
<input type="number" id="dnum" name="drivernumber" placeholder="Your employee number" required><br><br>
<label for="Date">Date Performed:</label><br>
<input type="date" id="date" name="date" required><br><br>
<label for="Time">Time Performed:</label><br>
<input type="time" id="time" name="time" value="now" required><br><br>
<label for="Tractor/Truck#">Tractor / Truck #:</label><br>
<input type="number" id="tractor/truck" name="tractor/truck" placeholder="Your vehicle number" required><br><br>
<label for="Odometer">Odometer Reading:</label><br>
<input type="number" id="odom" name="odometer reading" placeholder="Vehicle odometer reading" required><br><br>
<center><h3>Tractor / Truck Inspection:</h3></center>
<table id="Inspection" width="100%">
<tr>
<th> </th>
<th>Satisfactory</th>
<th>Unsatisfactory</th>
</tr>
<tr>
<th><label for="Air Compressor">Air Compressor</label></th>
<td><input type="radio" id="air compressor" name="AirCompressor" value="Sat" required></td>
<td><input type="radio" id="air compressor2" name="AirCompressor" value="Unsat" required></td>
</tr>
<tr>
<th><label for="Air Lines">Air Lines</label></th>
<td><input type="radio" id="air lines" name="AirLines" value="Sat" required></td>
<td><input type="radio" id="air lines2" name="AirLines" value="Unsat" required></td>
</tr>
<tr>
<th><label for="Battery">Battery</label></th>
<td><input type="radio" id="Battery" name="Battery" value="Sat" required></td>
<td><input type="radio" id="Battery2" name="Battery" value="Unsat" required></td>
</tr>
<tr>
<th><label for="Belts and Hoses">Belts and Hoses</label></th>
<td><input type="radio" id="Belts and Hoses" name="BeltsandHoses" value="Sat" required></td>
<td><input type="radio" id="Belts and Hoses2" name="BeltsandHoses" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Body">Body</label></th>
<td><input type="radio" id="Body" name="Body" value="Sat"required></td>
<td><input type="radio" id="Body2" name="Body" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Brake Accessories">Brake Accessories</label></th>
<td><input type="radio" id="Brake Accessories" name="BrakeAccessories" value="Sat"required></td>
<td><input type="radio" id="Brake Accessories2" name="BrakeAccessories" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Brakes, Parking">Brakes, Parking</label></th>
<td><input type="radio" id="Brakes, Parking" name="BrakesParking" value="Sat"required></td>
<td><input type="radio" id="Brakes, Parking2" name="BrakesParking" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Brakes, Service">Brakes, Service</label></th>
<td><input type="radio" id="Brakes, Service" name="BrakesService" value="Sat"required></td>
<td><input type="radio" id="Brakes, Service2" name="BrakesService" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Clutch">Clutch</label></th>
<td><input type="radio" id="Clutch" name="Clutch" value="Sat"required></td>
<td><input type="radio" id="Clutch2" name="Clutch" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Coupling Devices">Coupling Devices</label></th>
<td><input type="radio" id="Coupling Devices" name="CouplingDevices" value="Sat"required></td>
<td><input type="radio" id="Coupling Devices2" name="CouplingDevices" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Defroster/Heater">Defroster/Heater</label></th>
<td><input type="radio" id="Defroster/Heater" name="DefrosterHeater" value="Sat"required></td>
<td><input type="radio" id="Defroster/Heater2" name="DefrosterHeater" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Drive Line">Drive Line</label></th>
<td><input type="radio" id="Drive Line" name="DriveLine" value="Sat"required></td>
<td><input type="radio" id="Drive Line2" name="DriveLine" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Engine">Engine</label></th>
<td><input type="radio" id="Engine" name="Engine" value="Sat"required></td>
<td><input type="radio" id="Engine2" name="Engine" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Exhaust">Exhaust</label></th>
<td><input type="radio" id="Exhaust" name="Exhaust" value="Sat"required></td>
<td><input type="radio" id="Exhaust2" name="Exhaust" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Fifth Wheel">Fifth Wheel</label></th>
<td><input type="radio" id="Fifth Wheel" name="FifthWheel" value="Sat"required></td>
<td><input type="radio" id="Fifth Wheel2" name="FifthWheel" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Fluid Levels">Fluid Levels</label></th>
<td><input type="radio" id="Fluid Levels" name="FluidLevels" value="Sat"required></td>
<td><input type="radio" id="Fluid Levels2" name="FluidLevels" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Frame and Assembly">Frame and Assembly</label></th>
<td><input type="radio" id="Frame and Assembly" name="FrameandAssembly" value="Sat"required></td>
<td><input type="radio" id="Frame and Assembly2" name="FrameandAssembly" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Front Axle">Front Axle</label></th>
<td><input type="radio" id="Front Axle" name="FrontAxle" value="Sat"required></td>
<td><input type="radio" id="Front Axle2" name="FrontAxle" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Fuel Tanks">Fuel Tanks</label></th>
<td><input type="radio" id="Fuel Tanks" name="FuelTanks" value="Sat"required></td>
<td><input type="radio" id="Fuel Tanks2" name="FuelTanks" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Horn">Horn</label></th>
<td><input type="radio" id="Horn" name="Horn" value="Sat"required></td>
<td><input type="radio" id="Horn2" name="Horn" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Lights">Lights -<br> Head/Stop<br> Tail/Dash<br> Turn Indicators<br> Clearance/Marker</label></th>
<td><input type="radio" id="Lights" name="Lights" value="Sat"required></td>
<td><input type="radio" id="Lights2" name="Lights" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Mirrors">Mirrors</label></th>
<td><input type="radio" id="Mirrors" name="Mirrors" value="Sat"required></td>
<td><input type="radio" id="Mirrors2" name="Mirrors" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Muffler">Muffler</label></th>
<td><input type="radio" id="Muffler" name="Muffler" value="Sat"required></td>
<td><input type="radio" id="Muffler2" name="Muffler" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Oil Pressure">Oil Pressure</label></th>
<td><input type="radio" id="Oil Pressure" name="OilPressure" value="Sat"required></td>
<td><input type="radio" id="Oil Pressure2" name="OilPressure" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Radiator">Radiator</label></th>
<td><input type="radio" id="Radiator" name="Radiator" value="Sat"required></td>
<td><input type="radio" id="Radiator2" name="Radiator" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Rear End">Rear End</label></th>
<td><input type="radio" id="Rear End" name="RearEnd" value="Sat"required></td>
<td><input type="radio" id="Rear End2" name="RearEnd" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Reflectors">Reflectors</label></th>
<td><input type="radio" id="Reflectors" name="Reflectors" value="Sat"required></td>
<td><input type="radio" id="Reflectors2" name="Reflectors" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Safety Equipment">Safety Equipment -<br> Fire Extinguisher<br> Flags/Flares/Fusees<br> Reflective Triangles<br> Spare Bulbs and Fuses<br> Spare Seal Beam</label></th>
<td><input type="radio" id="Safety Equipment" name="SafetyEquipment" value="Sat"required></td>
<td><input type="radio" id="Safety Equipment2" name="SafetyEquipment" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Starter">Starter</label></th>
<td><input type="radio" id="Starter" name="Starter" value="Sat"required></td>
<td><input type="radio" id="Starter2" name="Starter" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Steering">Steering</label></th>
<td><input type="radio" id="Steering" name="Steering" value="Sat"required></td>
<td><input type="radio" id="Steering2" name="Steering" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Suspension System">Suspension System</label></th>
<td><input type="radio" id="Suspension System" name="SuspensionSystem" value="Sat"required></td>
<td><input type="radio" id="Suspension System2" name="SuspensionSystem" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Tire Chains">Tire Chains</label></th>
<td><input type="radio" id="Tire Chains" name="TireChains" value="Sat"required></td>
<td><input type="radio" id="Tire Chains2" name="TireChains" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Tires">Tires</label></th>
<td><input type="radio" id="Tires" name="Tires" value="Sat"required></td>
<td><input type="radio" id="Tires2" name="Tires" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Transmission">Transmission</label></th>
<td><input type="radio" id="Transmission" name="Transmission" value="Sat"required></td>
<td><input type="radio" id="Transmission2" name="Transmission" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Trip Recorder">Trip Recorder</label></th>
<td><input type="radio" id="Trip Recorder" name="TripRecorder" value="Sat"required></td>
<td><input type="radio" id="Trip Recorder2" name="TripRecorder" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Wheels and Rims">Wheels and Rims</label></th>
<td><input type="radio" id="Wheels and Rims" name="WheelsandRims" value="Sat"required></td>
<td><input type="radio" id="Wheels and Rims2" name="WheelsandRims" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Windows">Windows</label></th>
<td><input type="radio" id="Windows" name="Windows" value="Sat"required></td>
<td><input type="radio" id="Windows2" name="Windows" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Windshield Wipers">Windshield Wipers</label></th>
<td><input type="radio" id="Windshield Wipers" name="WindshieldWipers" value="Sat"required></td>
<td><input type="radio" id="Windshield Wipers2" name="WindshieldWipers" value="Unsat"required></td>
</tr>
<tr>
<th><label for="Other">Other</label></th>
<td><input type="radio" id="Other" name="Other" value="Sat"required></td>
<td><input type="radio" id="Other2" name="Other" value="Unsat"required></td>
</tr>
</table><br>
<label for="modal-heading">Sign in the box below:</label>
<div class="modal">
<div class="signature-panel"></div>
<div class="controls-panel">
<input type="button" class="btn btn--secondary clear-button" value="Clear"/>
</div>
</div>
<img id="rendered" src="" style="display:none">
<input type="Submit" class="Submit" value="Submit and close" onclick="renderSignature();saveImage();"/>
</div>
</form>
</body>
<script>
$('.signature-panel').jSignature();
$('.clear-button').on('click', function(e) {
e.preventDefault();
$('.signature-panel').jSignature("reset");
});
</script>
</html>
Here is a link to a video showing the issue I am having with this:
https://www.youtube.com/watch?v=h0OIJy_HgCQ&feature=youtu.be
And a link to the code:
https://www.w3schools.com/code/tryit.asp?filename=G8B90OFNIKOC
I need to maintain the form in its appearance while removing the white space. Please help!
As the title suggests, I have a scenario where, if the "Select All" radio button is checked, it must check all of the radio buttons in the columns below. Unfortunately, this is not working.
Here is a sample:
<table>
<thead>
<th>Role</th>
<th colspan="3">Access</th>
</thead>
<tbody>
<tr>
<td>Select All</td>
<td>
<input #none type="radio" name="access0" value="allNone"/>
<label>None</label>
</td>
<td>
<input #readOnly type="radio" name="access0" value="allReadOnly"/>
<label>Read Only</label>
</td>
<td>
<input #full type="radio" name="access0" value="AllFull"/>
<label>Full</label>
</td>
</tr>
<tr>
<td>Admin</td>
<td>
<input type="radio" name="access1" value="None" [checked]="none.checked"/>
<label>None</label>
</td>
<td>
<input type="radio" name="access1" value="ReadOnly" [checked]="readOnly.checked"/>
<label>Read Only</label>
</td>
<td>
<input type="radio" name="access1" value="Access" [checked]="full.checked"/>
<label>Full</label>
</td>
</tr>
<tr>
<td>Sales Person</td>
<td>
<input type="radio" name="access2" value="None" [checked]="none.checked"/>
<label>None</label>
</td>
<td>
<input type="radio" name="access2" value="ReadOnly" [checked]="readOnly.checked"/>
<label>Read Only</label>
</td>
<td>
<input type="radio" name="access2" value="Access" [checked]="full.checked"/>
<label>Full</label>
</td>
</tr>
</tbody>
</table>
And here is a link to a sample StackBlitz.
I am not sure why, for instance, all of the 'None' radio buttons are not checked when setting the [checked] as follow:
<input type="radio" name="access1" value="None" [checked]="none.checked"/>
disclamer it's not an answer, is an answer to a comment about use [(ngModel)] into a ReactiveForm.
#monstertjie_za, the doc indicate that you don't use in the same input TOGETHER formControlName and [(ngModel)], Not that you can not use a input into a reactive form. Imagine your example. You has a reactiveForm like
form=new FormGroup({
accessAdmin:new FormControl(),
accessPersonal:new FormControl()
})
But you want allow the user a rapid selection
<form [formGroup]="form">
<!--a input that not belong to the ReactiveForm that use [(ngModel)]-->
<div>
<label><input type="radio" value="None" [ngModelOptions]="{standalone:true}"
[ngModel]="access" (ngModelChange)="change($event)"/>None</label>
<label><input type="radio" value="ReadOnly" [ngModelOptions]="{standalone:true}"
[ngModel]="access" (ngModelChange)="change($event)"/>ReadOnly</label>
<label><input type="radio" value="Access" [ngModelOptions]="{standalone:true}"
[ngModel]="access" (ngModelChange)="change($event)"/>Access</label>
</div>
<!--inputs that belong to our formGroup-->
<div>
<label><input type="radio" value="None" formControlName="accessAdmin"/>None</label>
<label><input type="radio" value="ReadOnly" formControlName="accessAdmin"/>ReadOnly</label>
<label><input type="radio" value="Access" formControlName="accessAdmin"/>Access</label>
</div>
<div>
<label><input type="radio" value="None" formControlName="accessPersonal"/>None</label>
<label><input type="radio" value="ReadOnly" formControlName="accessPersonal"/>ReadOnly</label>
<label><input type="radio" value="Access" formControlName="accessPersonal"/>Access</label>
</div>
</form>
<pre>
{{form?.value|json}}
</pre>
where you has a function like
change(value) {
this.form.get('accessAdmin').setValue(value);
this.form.get('accessPersonal').setValue(value);
}
You can see the stackblitz demo
You see that we use a input with [(ngModel)] to help the user to change the value of form.accessAdmin and form.accessPersonal. It is not related with the link you show me and is perfectly formed -even I'll say that it's good to help the user-
Check for changes:
<table (click)="cd.detectChanges()">
<thead>
<th>Role</th>
<th colspan="3">Access</th>
</thead>
<tbody>
<tr>
<td>Select All</td>
<td>
<input #none type="radio" name="access0" value="allNone"/>
<label>None</label>
</td>
<td>
<input #readOnly type="radio" name="access0" value="allReadOnly"/>
<label>Read Only</label>
</td>
<td>
<input #full type="radio" name="access0" value="AllFull"/>
<label>Full</label>
</td>
</tr>
<tr>
<td>Admin</td>
<td>
<input type="radio" name="access1" [value]="None" [checked]="none.checked"/>
<label>None</label>
</td>
<td>
<input type="radio" name="access1" value="ReadOnly" [checked]="readOnly.checked"/>
<label>Read Only</label>
</td>
<td>
<input type="radio" name="access1" value="Access" [checked]="full.checked"/>
<label>Full</label>
</td>
</tr>
<tr>
<td>Sales Person</td>
<td>
<input type="radio" name="access2" value="None" [checked]="none.checked"/>
<label>None</label>
</td>
<td>
<input type="radio" name="access2" value="ReadOnly" [checked]="readOnly.checked"/>
<label>Read Only</label>
</td>
<td>
<input type="radio" name="access2" value="Access" [checked]="full.checked"/>
<label>Full</label>
</td>
</tr>
</tbody>
</table>
And TS:
import {ChangeDetectorRef, Component} from '#angular/core';
#Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
constructor(protected cd: ChangeDetectorRef){}
}
you have to use ngModel to update the radio button values like this -
app.component.html
<table>
<thead>
<th>Role</th>
<th colspan="3">Access</th>
</thead>
<tbody>
<tr>
<td>Select All</td>
<td>
<input type="radio" name="access0" value="allNone"
[(ngModel)]='none'/>
<label>None</label>
</td>
<td>
<input [(ngModel)]='readonly' type="radio" name="access0" value="allReadOnly"/>
<label>Read Only</label>
</td>
<td>
<input [(ngModel)]='full' type="radio" name="access0" value="AllFull"/>
<label>Full</label>
</td>
</tr>
<tr>
<td>Admin</td>
<td>
<input type="radio" name="access1" [value]="1" [checked]='none'/>
<label>None</label>
</td>
<td>
<input type="radio" name="access1" value="ReadOnly" [checked]='readonly'/>
<label>Read Only</label>
</td>
<td>
<input type="radio" name="access1" value="Access" [checked]="full"/>
<label>Full</label>
</td>
</tr>
<tr>
<td>Sales Person</td>
<td>
<input type="radio" name="access2" value="None" [checked]="none"/>
<label>None</label>
</td>
<td>
<input type="radio" name="access2" value="ReadOnly" [checked]="readonly"/>
<label>Read Only</label>
</td>
<td>
<input type="radio" name="access2" value="Access" [checked]="full"/>
<label>Full</label>
</td>
</tr>
</tbody>
</table>
app.component.ts
import { Component } from '#angular/core';
#Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
public none=false;
public readonly=false;
public full=false;
}
I have a 4x4 table of radiobuttons. In the first row (an extra row ABOVE the 4x4) I would like a button centered horizontally. I have tried colspan etc. but all still leave the radiobutton in a column like the others, and thus uncentered.
Obligatory Table-less Answer:
<div>
<div class="center"><input type='button' value='hello' /></div>
<ul class="radioList">
<li>
<label for="radio1">
<input type="radio" id="radio1" />
Checkbox 1</label>
</li>
<li>
<label for="radio2">
<input type="radio" id="radio2" />
Checkbox 2</label>
</li>
<li>
<label for="radio3">
<input type="radio" id="radio3" />
Checkbox 3</label>
</li>
<li>
<label for="radio4">
<input type="radio" id="radio4" />
Checkbox 4</label>
</li>
</ul>
</div>
.center { text-align:center; }
.radioList {
list-style:none;
width:100%;
}
.radioList li {
float:left;
width:25%;
}
http://jsfiddle.net/Amudt/
http://jsfiddle.net/EJbny/
<table style='width:100%;' border=1>
<tr>
<td colspan=4 style='text-align:center;'><input type='button' value='hello'></td>
Like this? Just use CSS and the text-align:center rule on the top row. Here's a jsFiddle example.
<table>
<tr>
<td colspan="4" style="text-align:center"><input type="radio" /></td>
</tr>
<tr>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
</tr>
<tr>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
</tr>
<tr>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
</tr>
<tr>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
<td><input type="radio" /></td>
</tr>
</table>