Last active
March 13, 2017 08:08
-
-
Save christaylor-hod/b10226562c7b4d88cd5aeb2559c0ef09 to your computer and use it in GitHub Desktop.
Resources for Prototype kit training
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Script to store things entered by the user in a series of | |
form transaction steps into the browsers local storage, then | |
insert everything from local storage into a hmtl list | |
Requires you to add a class of .store to any form input you | |
want to store | |
insert at end of document.ready | |
*/ | |
//on form submit... | |
$( "form" ).submit(function( event ) { | |
//loop through all of the inputs with class of store... | |
$('form .store').each(function (index, value) { | |
var thisKey = $(this).attr('name'); | |
var thisVal = $(this).val(); | |
//and store them in the browser session storage | |
sessionStorage.setItem(thisKey, thisVal); | |
}); | |
}); | |
/* | |
List all local storage items in an ul on the page. | |
Requires you to have an empty ul on a page with an | |
id of results-list | |
*/ | |
if ( $( "#results-list" ).length ) { | |
var i; | |
//removed the an item that the prototype kit automatically stores | |
sessionStorage.removeItem('prototypeWarning'); | |
for (i = 0; i < sessionStorage.length; i++) { | |
$('#results-list').append( | |
'<li>' + | |
'<strong style="font-weight:bold">' + | |
sessionStorage.key(i) + | |
'</strong> ' + | |
sessionStorage.getItem(sessionStorage.key(i)) + | |
'</li>' | |
); | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express') | |
var router = express.Router() | |
// Route index page | |
router.get('/', function (req, res) { | |
res.render('index') | |
}) | |
// add your routes here | |
router.get('/over-18', function (req, res) { | |
// get the answer from the query string (eg. ?over18=false) | |
var over18 = req.query.over18 | |
if (over18 === 'false') { | |
// redirect to the relevant page | |
res.redirect('under-18') | |
} else { | |
// if over18 is any other value (or is missing) render the page requested | |
res.render('over-18') | |
} | |
}) | |
//pass in value from query string into page | |
router.get('/done', function (req, res) { | |
var name = req.query.name | |
res.render('done', { 'name': name }) | |
}) | |
module.exports = router |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment