I have a form with information with user info:
<div>
<label for="nombre">Name</label>
<input type="text" required class="form-control" id="nombre" placeholder="Name" pattern="([A-Z][a-zA-Z]*)" />
</div>
<div>
<label for="apellido">Surname</label>
<input type="text" required class="form-control" id="apellido" placeholder="Surname" pattern="([A-Z][a-zA-Z]*)" />
</div>
<div>
<label for="email">Email</label>
<input type="email" required class="form-control" id="email" placeholder="Your email" />
</div>
<div>
<label for="domicilio">Mailing Address</label>
<input type="text" required class="form-control" id="domicilio" placeholder="Your address" />
</div>
<fieldset disabled>
<div>
<label for="comentario">Your information:</label>
<textarea id="comentario" rows="5" class="form-control"></textarea>
</div>
</fieldset>
<div>
<button type="submit" onclick="submitContacto()" class="btn btn-primary">Send</button>
</div>
This is the corresponding .js function
function submitContacto() {
var nombre = $("nombre").value;
var apellido = $("apellido").value;
var email = $("email").value;
var domicilio = $("domicilio").value;
localStorage.nombre = nombre;
localStorage.apellido = apellido;
localStorage.email = email;
localStorage.domicilio = domicilio;
}
I wanted to know how I can make it so when you click the button, the information of the localStorage appears in the textarea. I would like the textbox to show something like:
- Your name: (NAME)
- Your surname: (SURNAME) ...
submitbutton is pressed the page will redirect to theform actionand you won't have thetextareaon the page anymore, so trying to show it is a waste. You may want to have a regular button that the user first clicks which populates thetextareaand then after clicking it, that button gets hidden and the real submit button appears. Also, to set items inlocalStorageuselocalStorage.setItem("keyName", value).<form>that was not included in the question