-2
Good evening, could you help me? I’m trying to pass the data from one page to another but the field is empty. page 1: where I take the data. page 2: where I want to insert that data.
PAGE 1:
<h1 class="tituloProd">Arroz Tio João integral tipo 1 - 5KG</h1>
PAGE 2:
<p class="descricaoProduto">Descricao aqui<p>
$('#btnCompra').click (function(){
localStorage.setItem('tituloProd', 'arroz');
$('.descricaoProduto').text(localStorage.getItem('tituloProd'));
});
});
FULL JAVASCRIPT:
$(document).ready(function(){
$('#btnCompra').click (function(){
$('#modalProduto').modal('hide');
$('#divInfo').css('display','block'); /* exibe uma div de alerta */
var titulo = $('#tituloProd').text();
localStorage.setItem("titulo_produto", titulo);
});
$('#carrinho').click (function(){
$('#descricaoProduto').text(localStorage.getItem("titulo_produto"));
});
});
Good afternoon Leandrade! Thanks for the resolution, it worked! Now I have another problem. My goal was: when I clicked on the cart, the field was set in the product div, this worked, but the value appears for a short period of time and then disappears, IE, when I click on the cart, appears the field set and then disappears, Oce knows what can be?
– Weslley Fillipe
Put the whole function to see, with the code you posted has no way of knowing.
– LeAndrade
Ready! I’ve entered the full function
– Weslley Fillipe
Guy is very confused your code, but, by what posted not to see the pq is occurring this show behavior and then disappear, can be related to the ** $('#modalProduto'). modal('Hide');**, which is to hide the modal with id modalProduct.
– LeAndrade
Good evening Leandreade, I discovered the problem. My "btnCarrinho" was a link (<a>) and every time I clicked on it, the page updated. The reason the value disappeared did not understand, since localStorage remains after updates, but I removed the tag a and it worked all right.
– Weslley Fillipe