HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<form id="menuOrder">
<label>
<b id="slice"></b>
<input id="option1" type="radio" name="menuItem" value="pizza">
</label>
<br /><br />
<b id="toppings"></b>
<div id="topp"></div>
<br /><br />
<b id="sides"></b>
<div id="sid"></div>
<br /><br />
<b id="drinks"></b>
<div id="drink"></div>
<div id="sodasizes"></div>
<div id="drinkoption1"></div>
<div id="waters"></div>
<br/ ><br />
<input id="saveItOnly" type="button" value="Save and Submit" class="buttons"><br />
<button id="save_submit" type="submit" class="buttons">Your Order</button>
</form>
window.onload = ()=>{
localStorage.clear();
const data = {
"menu": {
"slice of pizza": "2.00", //holds input 0
"toppings": {
"pepperoni": ".25", //1
"meatballs": ".35", //2
"mushrooms": ".40", //3
"olives": ".20" //4
},
"sides": {
"potato salad": "1.25", //5
"hummus": "2.50", //6
"caesar salad": "3.50", //7
"garden salad": "2.25" //8
},
"drinks": {
"soda": {
"small": "1.95", //9
"medium": "2.20", //10
"large": "2.50" //11
},
"juice": "2.00", //12
"water": "1.25" //13
}
}
};
//setting variables to work with json
let pizzaMenu = data.menu;
let toppings = pizzaMenu.toppings;
let sides = pizzaMenu.sides;
let drinks = pizzaMenu.drinks;
let sodaSize = drinks.soda;
//setting variables to string information based on json data -- to use in radio input creations
let text = "";
let stext = "";
let dtext = "";
let sStext = "";
let gtext = "";
//setting data for main item of pizza from data
let mainI = (function() {
for (let prop in data.menu) {
for (x in data.menu){
let mainItem = x;
return mainItem.toUpperCase() + " - " + "$" + data.menu["slice of pizza"];
}
}
})();
document.getElementById("slice").innerHTML = mainI;
// printing radio inputs with toppings data
let first = (function() {
for (let prop in data.menu) {
if (data.menu.hasOwnProperty(prop)) {
for (x in data.menu){
if (x === "toppings"){
return x;
}
}
}
}
})();
document.getElementById("toppings").innerHTML = first.toUpperCase();
for (let t in toppings){
text += t.toUpperCase() + " - " + "$" + toppings[t] + "<input id='option_a' type='radio' name='menutoppings'>" + "<br />";
}
document.getElementById("topp").innerHTML = text;
// printing radio inputs with toppings data
let second = (function() {
for (let prop in data.menu) {
if (data.menu.hasOwnProperty(prop)) {
for (x in data.menu){
if (x === "sides"){
return x;
}
}
}
}
})();
document.getElementById("sides").innerHTML = second.toUpperCase();
for (let s in sides){
stext += s.toUpperCase() + " - " + "$" + sides[s] + "<input id='option' type='radio' name='menusides'>" + "<br>";
}
document.getElementById("sid").innerHTML = stext;
// printing radio input titles with drink [soda and water and juice] data
let third = (function() {
for (let prop in data.menu) {
if (data.menu.hasOwnProperty(prop)) {
for (x in data.menu){
if (x === "drinks"){
return x;
}
}
}
}
})();
document.getElementById("drinks").innerHTML = third.toUpperCase();
document.getElementById("waters").innerHTML = third;
for (let d in drinks){
dtext = d.toUpperCase();
break;
}
document.getElementById("drink").innerHTML = dtext;
// printing radio inputs with soda drink data
for (let sS in sodaSize){
sStext += sS + " - " + "$" + sodaSize[sS] + "<input id='option' type='radio' name='soda'>" + "<br />";
document.getElementById("sodasizes").innerHTML = sStext;
}
document.getElementById("sodasizes").innerHTML = sStext;
// printing radio inputs with juice data
let thirdjuice = (function() {
for (let prp in data.menu.drinks) {
if (data.menu.drinks.hasOwnProperty(prp)) {
for (x in data.menu.drinks){
if (x === "juice"){
return x + " - " + "$" + data.menu.drinks[x] + "<input id='option' type='radio' name='drinkchoice' value='juice'>" + "<br />";
}
}
}
}
})();
document.getElementById("drinkoption1").innerHTML = thirdjuice.toUpperCase();
// printing radio inputs with water data
let thirdwater = (function() {
for (let property in drinks) {
if (drinks.hasOwnProperty(property)) {
for (z in drinks) {
if (z === "water"){
return z.toUpperCase() + " - " + "$" + drinks[z] + "<input id='option' type='radio' name='drinkchoice' value='water'>" + "<br />";
}
}
}
}
})();
document.getElementById("waters").innerHTML = thirdwater;
}
//itsSaved is used within the showOrder() function to detect what conditoins should be used
let itsSaved = false;
//when called it saves the selected inputs into local storage when the "save and submit" button is clicked
function saveIt(){
var theSliceOfPizza = document.getElementById("option1");
if(theSliceOfPizza.checked){
localStorage.setItem("menu item", theSliceOfPizza.value);
}
var toSave = document.querySelectorAll("input");
if (toSave[1].checked){
toSave[1].value = "pepperoni";
localStorage.setItem("topping", toSave[1].value);
}
if (toSave[2].checked){
toSave[2].value = "meatballs";
localStorage.setItem("topping", toSave[2].value);
}
if (toSave[3].checked){
toSave[3].value = "mushrooms";
localStorage.setItem("topping", toSave[3].value);
}
if (toSave[4].checked){
toSave[4].value = "olives";
localStorage.setItem("topping", toSave[4].value);
}
if(toSave[5].checked){
toSave[5].value = "potato salad";
localStorage.setItem("side", toSave[5].value);
}
if(toSave[6].checked){
toSave[6].value = "hummus";
localStorage.setItem("side", toSave[6].value);
}
if(toSave[7].checked){
toSave[7].value = "ceasar salad";
localStorage.setItem("side", toSave[7].value);
}
if(toSave[8].checked){
toSave[8].value = "garden salad";
localStorage.setItem("side", toSave[8].value);
}
if(toSave[9].checked){
toSave[9].value = "small soda";
localStorage.setItem("drink", toSave[9].value);
}
if(toSave[10].checked){
toSave[10].value = "medium soda";
localStorage.setItem("drink", toSave[10].value);
}
if(toSave[11].checked){
toSave[11].value = "large soda";
localStorage.setItem("drink", toSave[11].value);
}
if(toSave[12].checked){
toSave[12].value = "juice";
localStorage.setItem("plusdrink1", toSave[12].value);
}
if(!toSave[12].checked){
toSave[12].value = "none";
localStorage.setItem("plusdrink1", toSave[12].value);
}
if(toSave[13].checked){
toSave[13].value = "water";
localStorage.setItem("plusdrink2", toSave[13].value);
}
if(!toSave[13].checked){
toSave[13].value = "none";
localStorage.setItem("plusdrink2", toSave[13].value);
}
const retrievedObject1 = localStorage.getItem('menu item');
const retrievedObject2 = localStorage.getItem('topping');
const retrievedObject3 = localStorage.getItem('side');
const retrievedObject4 = localStorage.getItem('drink');
const retrievedObject5 = localStorage.getItem('plusdrink1');
const retrievedObject6 = localStorage.getItem('plusdrink2');
const formOrder = {order:[retrievedObject1, retrievedObject2, retrievedObject3, retrievedObject4, retrievedObject5, retrievedObject6]};
localStorage.setItem('USER ORDER', JSON.stringify(formOrder));
alert('Order Is Saved\nClick the "Your Order" button to view your order.');
itsSaved = true;
}
//when the order button is clicked this funcion is called and performs conditionals to interact with the user
function showOrder(){
let radios = document.querySelectorAll('input[type="radio"]');
//if the "save and submit" button is clicked check conditionals
if(itsSaved === true){
var retrieveOrder = localStorage.getItem('USER ORDER');
let eagleEye = JSON.parse(retrieveOrder);
let checker = 0;
for(let i=0;i <eagleEye.order.length;i++){
if(eagleEye.order[i] === null || eagleEye.order[i] === "none"){
checker += 1;
}
}
//if the save and submit button is clicked with no selections
if(checker === 6){
localStorage.clear();
alert("Your order is empty, please select an item, then save and submit your selection.");
console.log(checker + ": saved without selecting items");
itsSaved = false;
return false;
}
//if checker condition is met print users selection as order
let statement = "YOUR ORDER IS:" + "\n";
for(let i=0;i<eagleEye.order.length;i++){
if(eagleEye.order[i] === "none"){
eagleEye.order.splice(i, 1);
}
}
let outputArr = [];
for(let el of eagleEye.order){
if(el !== null){
outputArr.push(el);
}
}
let jjj= outputArr.filter(el => el!=="none").forEach((el)=>{
statement += el + "\n";
});
confirm(statement);
//resetting values to perform function again
localStorage.clear();
radios.forEach((el)=>{
el.checked = false;
});
itsSaved = false;
}else{
//if the save and submit button not clicked but inputs are selected
for(let i=0;i<radios.length;i++){
if(radios[i].checked){
alert("Please save and submit your selection.");
return false;
}
}
//else alert for user to make a selection
alert("Please select an item and click the save and submit button before viewiung your order.");
}
}
//for "saveandsubmit" button and "order" button events
const savesubbuttons = document.querySelectorAll(".buttons");
const btnElems = [...savesubbuttons];
btnElems.forEach((btn)=>{
btn.addEventListener("click",(e)=>{
if(btn.type === "button"){
saveIt();
e.preventDefault();
}
if(btn.type === "submit"){
e.preventDefault();
showOrder();
}
});
});
Also see: Tab Triggers