I have a button that when clicked on it, localStorage takes its id, there it plays the id to the other page, but when I click on the button it is not pointing to the other page, it is only changing the url to the name of the page that is more "button = 1".
HTML:
<input id="inicio" type="date">
<input id="fim" type="date">
<button onclick="postData();">gerar</button>
<div id="dados">
JAVASCRIPT:
function postData() {
var inicio, fim;
inicio = document.getElementById('inicio').value;
fim = document.getElementById('fim').value;
// Default options are marked with *
fetch('http://api_aqui', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'inicio=${inicio}&fim=${fim}'
}).then(response => response.json().then(data => ({
data: data,
status: response.status
})
).then(res => {
res.data.map(element => {
console.log(element.PRODUTO)
console.log(element.ID)
$('#dados').append('
<h3>${element.PRODUTO}</h3>
<br>
<form id="form">
<button onClick="pegar(this);" name="botao" value="${element.ID}" href="pagina.php">pegar</button>
<form>
')
})
})
)
}
function pegar(botao) {
window.localStorage.setItem('produto', '${botao.value}')
}