1
I need some help from you.
I have two numeric fields in my system as shown in the photo below.
The field that has a red line around it, it will have to make a calculation about the top field, as you can see in the field Creatinine... this with a value of 2.3, the field in red would only accept that value of 2.3 + 0.3 in case it would be 2.6 up.
In short, the field in red would accept only the values of the top field plus 0.3, as an example would be 2.6 for more, could not accept values below that
I’ll post my code I tried to do here:
function formulaCreabas2() {
var valueCreabas2 = $('[name="creabas2"]').val();
var valueCrebas = $('[name="creabas"]').val();
var subCreab = valueCrebas - valueCreabas2
console.log(subCreab);
if (subCreab < 0.2999999999999997) {
$('#creabas2-msg').removeClass('display-none');
$('#creabas2-msg').text('Não há como comprovar a informação. Dúvidas: entre em contato com a equipe do estudo.');
$('[name = "creabas2"]').val('');
} else {
$('#creabas2-msg').addClass('display-none');
}
}
<div class="row">
<div class="form-group topo">
<div class="col-md-4">
<label>
Creatinina (posterior à admissão hospitalar e a mais próxima da randomização): <span style="color:red;">*</span>
</label>
</div>
<div class="col-md-3 target">
<div style="width: 180px;" class="input-group">
<input type="text" class="form-control" placeholder="00.00" value="creabas" name="creabas" min="0" max="15" />
<div style="background: #E0E1E2;" class="input-group-addon">mg/dL</div>
</div>
</div>
<div class="col-md-3">
<label id="creabas-error" class="input-error" for="creabas" style="border: none; color: red;"></label>
</div>
</div>
</div>
<div class="row" id="creba2nd">
<div class="form-group topo">
<div class="col-md-4">
<label>
Se necessário, informe mais uma medida da creatinina nas 48 horas prévias a randomização, que comprove a elevação de 0,3mg/dL ou incremento de 50% no valor basal: <span style="color:red;">*</span>
</label>
</div>
<div class="col-md-3 exibeEsconde">
<div style="width: 180px;" class="input-group">
<input type="text" class="form-control " placeholder="00.00" value="creabas2" name="creabas2" min="0" max="15" />
<div style="background: #E0E1E2;" class="input-group-addon">mg/dl</div>
</div>
</div>
<div class="col-md-3">
<label id="creabas2-error" class="input-error" for="creabas2" style="border: none; color: red;"></label>
<label id="creabas2-msg" class="text-danger display-none" for="creabas2"></label>
</div>
</div>
</div>
creabas is the variable of the first field, Creatinine...
creabas2 is the field variable If necessary...
You can add HTML for testing?
– Sergio
just a moment I’ll create here
– Leonardo Macedo
https://jsfiddle.net/w8p14wx3/
– Leonardo Macedo
Leonardo, can you ask me some questions about your question? 1- When the calculation of possible values should occur, that is, when the formulaCreabas2() function should be called. 2- The idea is that the value of the second input is always higher than the value of the first + 0.3, that is, any values greater than or equal to X+0.3?
– Caique Romero