1
I have the following problem:
I have a field that I put a value on input
and it analyzes whether the value placed inside is within the switch
who is in the Javascript. He’s making the following mistake:
Uncaught Typeerror: Cannot read Property 'value' of null.
The code is as follows::
<input type="text" name="" id="nome" value="">
<button type="button" onclick="myfunction() ">Aperte</button>
<p id="pnome"></p>
var fruta = document.getElementById("nome").value;
function myfunction(){
switch (fruta) {
case "Laranjas":
document.write("As laranjas custam R$0,59 o kg");
break;
case "Maçãs":
document.write("As maçãs custam R$1,50 o kg");
break;
case "Bananas":
document.write("As bannas custam R$3,00 o kg");
default:
document.write("Desculpe, estamos sem nenhuma " + fruta + ".");
}
}
document.getElementById("pnome").innerHTML = "nome: " + fruta;
vlw man worked. Thank you
– Marcos Mamede