I have the following form:
<input type="number" min="0" value="0" />
<input type="number" min="0" value="0" />
<input type="number" min="0" value="0" />
<input type="number" min="0" value="0" />
<button>GERAR</button>
In it the user selects the value of the border width in the following block:
<div class="forma"></div>
I created the method gerar()
const gerar = _ => {
let widths = [];
cps.forEach(c => widths.push('${c.value}px'));
frm.style.borderStyle = 'solid';
frm.style.borderWidth = widths.join(' ');
};
which traverses the object cps
and adds its value to the object widths
, then sets the property borderWidth
to the values of the object widths
.
So far so good, as you can see below the code works normally.
let btn = document.querySelector('button');
let cps = document.querySelectorAll('[type="number"]');
let frm = document.querySelector('.forma');
const gerar = () => {
let widths = [];
cps.forEach(c => widths.push('${c.value}px'));
frm.style.borderStyle = 'solid';
frm.style.borderWidth = widths.join(' ');
};
btn.onclick = gerar;
input[type="number"] {
width: 40px;
}
.forma {
height: 100px;
margin: 14px;
width: 100px;
}
<input type="number" min="0" value="0" />
<input type="number" min="0" value="0" />
<input type="number" min="0" value="0" />
<input type="number" min="0" value="0" />
<button>GERAR</button>
<div class="forma"></div>
The problem
One of these fields may have its value greater than the others, eg 0 10 60 10 / 50 20 20 40 .
I have to set the borderColor
property and the field that has its largest value, will have the different color, eg:
0 10 60 10 = "transparent #f7f7f7 #069 #f7f7f7"
50 20 20 40 = "#069 #f7f7f7 #f7f7f7 #f7f7f7"
How can I resolve?