Skip to content

Instantly share code, notes, and snippets.

@shaedrich
Forked from anonymous/index.html
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaedrich/d7ad174e6e1cc7cd598c to your computer and use it in GitHub Desktop.
Save shaedrich/d7ad174e6e1cc7cd598c to your computer and use it in GitHub Desktop.
Enable a multipage/multistep form and store data in SessionStorage

Hier findest du ein einfaches Beispiel, wie du mehrere Formulare und auch Infotexte so kombinieren kannst, dass die Daten erst clientseitig gespeichert werden und später gebündelt zur Verfügung stehen, um beispielsweise an eine serverseitige Scriptsprache gesendet zu werden.

See it in action: http://codepen.io/anon/pen/zxLqqp

<form id="schritt1" method="get">
<input type="text" name="firstname" />
<input type="text" name="lastname" />
<input type="submit" />
</form>
<div class="info">
Bla bla
<button id="weiter">Weiter</button>
</div>
<form id="schritt3" method="get">
<select name="auswahl">
<option name="dies">Dies</option>
<option name="das">Das</option>
</select>
<input type="submit" />
</form>
$('form#schritt1').submit(function (ev) {
ev.preventDefault();
var firstname = $('input[name=firstname]').val();
var lastname = $('input[name=lastname]').val();
window.sessionStorage.setItem('firstname',firstname);
window.sessionStorage.setItem('lastname',lastname);
$(this).hide();
$('.info').show();
console.log(firstname,lastname)
});
$('#weiter').click(function () {
$(this).parent().hide();
$('form#schritt3').show();
});
$('form#schritt3').submit(function (ev) {
ev.preventDefault();
var auswahl = $('select').find('option:selected').val();
window.sessionStorage.setItem('auswahl',auswahl);
$(this).hide();
$('body').html('<strong>Eingegebene Daten:</strong><br />' + window.sessionStorage.getItem('firstname') + ' ' + window.sessionStorage.getItem('lastname') + ' <br />Auswahl: ' + window.sessionStorage.getItem('auswahl'))
});
.info, form#schritt3 {
display: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment