Hello, is it possible yes.
I made a simple code with comments that will help you understand how to do this:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
window.onload = function() {
//Uso de localStorage
//var name = localStorage.getItem("name");
//var email = localStorage.getItem("email");
//var phone = localStorage.getItem("phone");
var name = sessionStorage.getItem("name");
var email = sessionStorage.getItem("email");
var phone = sessionStorage.getItem("phone");
if (name !== null) $('#inputName').val(name);
if (email !== null) $('#inputEmail').val(email);
if (phone !== null) $('#inputPhone').val(phone);
}
function myFunction() {
//Uso de localStorage
//window.localStorage.setItem("name", $('#inputName').val());
//window.localStorage.setItem("email", $('#inputEmail').val());
//window.localStorage.setItem("phone", $('#inputPhone').val());
sessionStorage.setItem("name", $('#inputName').val());
sessionStorage.setItem("email", $('#inputEmail').val());
sessionStorage.setItem("phone", $('#inputPhone').val());
location.reload(true);
}
</script>
</head>
<body>
<div class="form-actions">
<form>
<table cellpadding = "5" cellspacing ="10">
<tr class="control-group">
<td style="width: 100px;">
<div>Name: <font color="red">(*)</font></div>
</td>
<td>
<input type="text" id="inputName" placeholder="Nome" required>
</td>
</tr>
<tr class="control-group">
<td>
<div>Email: <font color="red">(*)</font></div>
</td>
<td>
<input class="span3" placeholder="Email" id= "inputEmail" type="email" required>
</td>
</tr>
<tr class="control-group">
<td>
<div>Phone: </div>
</td>
<td>
<input type="text" id="inputPhone" placeholder="Telefone">
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<button id="btnConfirm" class="btn btn-primary" onclick="myFunction();">Carregar a página</button>
<input type="reset" value="Limpar" id="btnReset" class="btn"/>
</div>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
Note: Just copy this paste code into a . html file to test locally.
Good studies and I hope I’ve helped!
Can use
sessionStorage
orlocalStorage
for this.– Renan Gomes
Can you help me with an example of how to do it with one of the two ?
– KevinF
The ideal is to use Ajax in the new window and dynamically add a new item in the combo without refreshing the page.
– Sam
@Kevin. F managed to use the example I created to help him ?
– RXSD