I have the following code:
<script type="text/javascript">
function id(el) {
return document.getElementById( el );
}
function altura( un, quanti_imagens ) {
return parseFloat(un.replace(',', '.'), 10) / parseFloat(quanti_imagens.replace(',', '.'), 10);
}
window.onload = function() {
id('passo').addEventListener('keyup', function() {
var result = altura( this.value , id('quanti_imagens').value );
id('altura').value = String(result.toFixed(2)).formatMoney();
});
id('quanti_imagens').addEventListener('keyup', function(){
var result = altura( id('passo').value , this.value );
id('altura').value = String(result.toFixed(2)).formatMoney();
});
}
String.prototype.formatMoney = function() {
var v = this;
if(v.indexOf('.') === -1) {
v = v.replace(/([\d]+)/, "$1,00");
}
v = v.replace(/([\d]+)\.([\d]{1})$/, "$1,$20");
v = v.replace(/([\d]+)\.([\d]{2})$/, "$1,$2");
v = v.replace(/([\d]+)([\d]{3}),([\d]{2})$/, "$1.$2,$3");
return v;
};
You are in the PHP File ( <!DOCTYPE html>
). It works perfectly.
Value of input passo
/ by "Step" the value of the input quanti_imagens
, but it is appearing NaN
until the two input fields .
How do I delete this?