1
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>
On 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
with the values of the object widths
.
So far so good, as can be seen 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 higher than the others, ex: 0 10 60 10 / 50 20 20 40.
I have to define the property borderColor
and the field that has its highest value, will have the different color, ex:
0 10 60 10 = "transparent #f7f7f7 #069 #f7f7f7"
50 20 20 40 = "#069 #f7f7f7 #f7f7f7 #f7f7f7"
How can I solve ?