-1
I’m practicing in JS and decided to create a program... a barbecue grill.
The point is, I created two pages index.html and the second so that when the user click the button calcular, it is redirected there, and the values load on this second page in list form.
I pointed both pages to the same Javascript file. The problem is that I don’t know what I’m doing wrong, because when I click the button, I get redirected to the second screen, but it doesn’t load the values as I wanted.
I wonder if you can help me by pointing out what I’m doing wrong?
index.html document:
<center class="container">
<div class="card border-dark mb-3 my-5" style="max-width: 30rem;">
<div class="card-header"><h3>Churrascômetro</h3></div>
<div class="card-body text-dark">
<form action="lista.html">
<input type="number" id="adultos" class="form-control my-3 col-8" placeholder="Adultos">
<input type="number" id="criancas" class="form-control my-3 col-8" placeholder="Crianças">
<input type="number" id="duracao" class="form-control my-3 col-8" placeholder="Duração">
<button type="submit" id="btnCalc"class="my-5 col-8 btn btn-outline-dark btn-lgbtn-block">Calcular</button>
<div></div>
</form>
</div>
</div>
</center>
HTML of the second page:
center class="container">
<div class="card border-dark mb-3 my-5" style="max-width: 30rem;">
<div class="card-header"><h3>Lista de compras</h3></div>
<div class="card-body text-dark">
<a href="index.html" role="button" class="btn btn-outline-dark btn-block col-4">Novo Churrasco</a>
<div id="lista"></div>
</div>
</div>
</center>
Javascript code:
var adultos = document.querySelector("#adultos")
var criancas = document.querySelector("#criancas")
var duracao = document.querySelector("#duracao")
var btnCalc = document.querySelector("#btnCalc")
var lista = document.querySelector("#lista")
btnCalc.onclick = function(e){
e.preventDefault
lista.innerHTML = "teste"
}
where on your page you are redirecting to another?
– iwaduarte
Explain some things that are not clear: Where is
HTML da segunda página:would be the pagelista.html? This javascript loose code belongs to which page? Your intention is to pass the values of the form fields on the pageindex.htmlfor the element<div id="lista"></div>of the html where it is writtenHTML da segunda página:?– Augusto Vasques
You can pass the data from one page to another by placing
namein the form fields, and notid.– Sam