JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" name="network_top_cashback" id="network_top_cashback" value="" size="4" class="inputt" />
<br>
<input type="text" name="cashback_coef" id="cashback_coef" value="" size="4" class="inputt" />
<br>
<input type="text" readonly="readonly" name="member_top_cashback" id="member_top_cashback" value="" size="4" class="inputt" />
JavaScript
$(document).ready(function () {
$("#network_top_cashback, #cashback_coef").change(function() {
$("#member_top_cashback").val($("#network_top_cashback").val() * $("#cashback_coef").val());
var num =$("#member_top_cashback").val();
num = num.toFixed(2);
});
});
$( function() {
$('#network_top_cashback').keyup(function(){
if($(this).val().indexOf('.')!=-1){
if($(this).val().split(".")[1].length > 2){
if( isNaN( parseFloat( this.value ) ) ) return;
this.value = parseFloat(this.value).toFixed(2);
}
}
return this;
});
});
$( function() {
$('#cashback_coef').keyup(function(){
if($(this).val().indexOf('.')!=-1){
if($(this).val().split(".")[1].length > 5){
if( isNaN( parseFloat( this.value ) ) ) return;
this.value = parseFloat(this.value).toFixed(2);
}
}
return this;
});
});
$('input#member_top_cashback').blur(function(){
var num = parseFloat($(this).val());
var cleanNum = num.toFixed(2);
$(this).val(cleanNum);
});