0
I would like to know how I can validate an input based on its value.
I have the following div with input and button:
<div class="input-group form-frete">
<input class="form-control" type="text" placeholder="00000-000"name="txtFrete" />
<button class="btn btn-light" onclick="javascript: btn_click()">Calcular</button>
</div>
I would like when inserting the value 35500000 in the txtFrete input and clicking on calculate, to be returned in the div just below the value: 55
<div>
O valor do frete é: "Aqui seria o 55"
</div>
I started doing a js, but I believe I’m completely wrong:
let valorFrete = "55";
let cep = txtFrete.value;
function btn_click() {
if (cep == txtFrete.value) {
console.log = ("55 reais");
} else {
console.log = ("Tente outro cpf")
}
}
Is returning "Uncaught Referenceerror: btn_click is not defined at Htmlbuttonelement.onclick (perfume1.html:162)" When I click the calculate button. On line 162 you have: <button class="btn btn-light" onclick="btn_click();">Calculate</button>
– Gabriel Melo
Gabriel, I updated the code by tag
<script>
. Please make sure you answer it. The message variable was also wrong, I had putvCep
but I changed it tovFrete
– Rodrigo Tognin
Thank you very much friend, it worked perfectly!
– Gabriel Melo