1
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;
};
It’s in the PHP File (<!DOCTYPE html>
). Works perfectly.
Value of input passo
/ by "Step" the value by input quanti_imagens
, but is appearing NaN
up to the completion of the two input fields.
How do I eliminate that?
Include html, elements with the ids "step" and "quanti_images" are inputs?
– Leandro Angelo