Creating a dynamic menu-planning page and shopping list

I have a page on my site that allows users to create a shopping list from seven dinner recipes and one dessert, Users can deselect ingredients that are already onhand so that these items are not included on the shopping list.  You can see the page as it currently functions here: http://www.whatsfordinner.net/meals.html My goal is to expand the user interactiveness by allowing visitors to deselect meals they don’t wish to serve and replace them with other meals from the site.  Using the example Dynamically Add/Remove rows in HTML table using JavaScript: https://www.viralpatel.net/dynamically-add-remove-rows-in-html-table-using-javascript/ I have been successful (with Viral’s help) in creating the code that will allow users to remove the meals they don’t wish to include.  I then set and retrieved my first cookie (the setting part wasn’t so hard, but I am still a bit fuzzy on parts of the read cookie function) so that the users choices are saved when the page is exited.  You can see it work here: http://www.whatsfordinner.net/Testing-Cookie-Set.html Now I’m ready for the next step, moving information from another page and placing it into the first page.  I am using  getElementById to capture a div section with a cookie and (hopefully) move that information via the cookie and document.write the variable onto the first page.  I’m beginning to wonder if that can be done.
var newMeal = document.getElementsByName('groceries'); var expires = new Date(); expires.setTime (expires.getTime() + 24 * 60 * 60 * 1000); var expiryDate = expires.toGMTString(); function newCookie(add,newMeal) { document.cookie = add + "=" + newMeal + "; expires=" + expiryDate; } function toShoppingList() { window.location = "http://www.whatsfordinner.net/Testing-Insert-div.html"; } <div id="groceries"> Shopping list for a new meal </div> <form onClick="toShoppingList();" "newCookie();"> <input type="button" value="Add this meal to my menu and shopping list"> </form>
Code language: JavaScript (javascript)
If it is possible to carry the entire div with a cookie, I now need to write the cookie function to read the data.  Since I had success with the previous getCookie, I altered that function for the new variable
Code language: JavaScript (javascript)
function getCookie(add) { var cookieFound = false; var start = 0; var end = 0; var cookieString = document.cookie; var i = 0; //Scan the cookie for add while (i http://www.whatsfordinner.net
Share
Published by
Jean Fisher
Tags: dynamic menu How-To JavaScript

Recent Posts

  • Java

Java URL Encoder/Decoder Example

Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…

5 years ago
  • General

How to Show Multiple Examples in OpenAPI Spec

Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…

5 years ago
  • General

How to Run Local WordPress using Docker

Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…

5 years ago
  • Java

Create and Validate JWT Token in Java using JJWT

1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…

5 years ago
  • Spring Boot

Spring Boot GraphQL Subscription Realtime API

GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…

5 years ago
  • Spring Boot

Spring Boot DynamoDB Integration Test using Testcontainers

1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…

5 years ago