-1
Good afternoon,
I have the following problem. I am creating a button to calular logarithm inside a calculator. so I found in the link on this link the possibility to make Lulo. I appreciate the help. The result was to be displayed on the display but everything is empty.
function logaritmo( x, y) {
return Math.log(y) / Math.log(x);
}
But I want the above function to be executed in the algorithm below.
function calculoLogaritmo() {
var vis = document.calcform.visor;
var element = document.getElementById('elemento');
var logaritmo = document.getElementById('log');
var base = document.getElementById('base');
var resultado;
element.innerHTML = 'O logaritmo de <input id="log" type="text"/> na base <input id="base" type="text"/> ';
if(isNaN(Number(logaritmo.value)) && isNaN(Number(base.value)) || Number(logaritmo.value) == "" && Number(base.value) == "" ){
alert("Favor informa valores validos para a execução do resultado");
} else{
resultado = logaritmo(Number(base.value), Number(logaritmo.value));
}
vis.value = resultado;
}
Follows the html
<form name="calcform" method="post" action="">
<p id="elemento"></p>
<input type="text" name="visor" id="visor" value=""/>
<td><input type="button" name="logaritmo" class="formula" value="log" title="logaritmo" onclick="calculoLogaritmo()" /></td>
</form>
And what behavior was expected? What behavior is occurring?
– Sorack
The expected behavior was that the result appears in the display but it is empty.
– Moises Moraes
Put that information in your question then
– Sorack
The name
logaritmo
is used 2x in your code, both for the function you are using to do the calculation and for the HTML element you are picking up withdocument.getElementById()
. This could be your problem, rename one of the two.– fernandosavio