2
Good afternoon Amigos
I have an input with the name of MARGIN, where a value is displayed according to some calculations that are made... I need the input to change the color to red if this value is less than 25, if it is larger it keeps its color (white)...
NOTE: I have the Value input, where this input the sellers manipulate the value of a product always trying to keep the margin above 25%, but if it lowers I want the color change, all this refresh.
<label for="valor_unitario">Vlr. Unit.</label>
<input type="text" name="valor_unitario" id="valor_unitario" style="text-align: center" required>
<label for="quantidade">Qtd.</label>
<input type="text" name="quantidade" id="quantidade" style="text-align: center" required>
<label for="valor_total">Vlr. Total</label>
<input type="text" name="valor_total" id="valor_total" readonly>
<label for="margem">Margem</label>
<input type="text" name="margem" id="margem" style="text-align: center" readonly>
In order not to be lost, the total value input shows the value of (unitary value * quantity).. what interests us is unitary value and margin
Can you post the code? is easier to search for a specific and simple solution for your case.
– brnTwp
edited the question
– Nicholas Ruschel Krüger
You could "watch" the input with javascript, every time there was a change, change the background-color of the input.
document.getElementById('input').addEventListener('input',function(e){ console.log('alterado');});
– Victor Jordan
however as I would do in case to change only if the value is below 25?
– Nicholas Ruschel Krüger
A condition within this eventListener I believe would solve :) for example:
if (input.value > 25){ //logica } else { //logica }
– Victor Jordan
I gave a summary, but I think I can understand the logic hehe If this fits, I can post a version more explained as answer :)
– Victor Jordan
I was doing this function but I don’t know what to wander window.onload = Function(){ $("#valor_unitario"). Blur(Function() { var margin = $('#margin'). val(); var bgcolor = margin < 25 ? '#B20000' '#fff'; Document.getElementById('margin').style.backgroundColor = bgcolor; } }
– Nicholas Ruschel Krüger
I posted a Codepen that does what you want, I hope! If I need to change :)
– Victor Jordan