473,320 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using JS to set and use cookies

I can set cookies in JS but cant wrap my mind around how to use them for example in this case the cookie value is a button that I want to put in a div so the client can use it. I know this question is vague but I am doing things never done before.

My main site is http://videosanctuary.com/bot.html Click image for video and you will get an idea what I am doing.

The partial site in question here is https://q17news.tech/template.php
(TOC)
Expand|Select|Wrap|Line Numbers
  1. <script>
  2.      epv = document.getElementById("tr").innerHTML;
  3.   document.getElementById("col2").innerHTML=epv;
  4.    //document.cookie = "up=upv; expires=Sun, 1 January 2019 12:00:00 UTC;";
  5.    //  document.cookie = "name=James; expires=Sun, 1 January 2019 12:00:00 UTC;";
  6.        // deleteCookie("up");
  7.        // deleteCookie("name");
  8.    console.log(document.cookie);
  9.      //alert(document.cookie);
  10.  
  11.     </script>    
  12.  
  13. <script> 
  14.     function bake(){ 
  15.         const epv =document.getElementById("tr").innerHTML; alert("epv"+" "+epv);
  16.         epv = document.getElementById("tr").innerHTML;
  17.         setCookie("ep", epv, 30);  alert("ep"+" "+ep);
  18.     }
  19.     function createFunction(){        
  20.         var name = document.getElementById("n1").value;  
  21.          document.getElementById("tr").innerHTML=UE+bt1 +time+bt2 + name +bt3;
  22.        let upv =document.getElementById("tr").innerHTML; 
  23.         setCookie("up", upv, 30);
  24.         setCookie(cname,cvalue,exdays) 
  25.           const d = new Date();
  26.           d.setTime(d.getTime() + (exdays*24*60*60*1000));
  27.           let expires = "expires=" + d.toUTCString();
  28.           document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  29.  
  30.  
  31.     }
  32.   function checkCookie() { alert(upv);
  33.   let upv = getCookie("up");
  34.   if (upv != "") {
  35.      alert("yes");
  36.   } else {
  37.     alert("nope");
  38.       deleteCookie("username");
  39.      }
  40.   }
  41. function getCookie() {
  42.   const getCookie = ep => {
  43.   const cookies = document.cookie.split(';')
  44.   for (let i = 0; i < cookies.length; i++) {
  45.     let c = cookies[i].trim().split('=')
  46.     if (c[0] === ep) {
  47.       return decodeURIComponent(c[1])
  48.     }
  49.   }
  50.   return ''
  51. }
  52. function setCookie(cname,cvalue,exdays) {
  53.   const d = new Date();
  54.   d.setTime(d.getTime() + (exdays*24*60*60*1000));
  55.   let expires = "expires=" + d.toUTCString();
  56.   document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  57. }      
  58. </script>
.
Feb 12 '23 #1
0 1484

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mandy Holmes | last post by:
Hi all (Newbie alert!) I am a bit stuck. I want to set a cookie when a hyperlink on my website is clicked. This cookie will then be used to determing which of 5 images is displayed on that page...
0
by: Amit Jamgade | last post by:
Hi, I am making use of cookies to store the Session State information through JavaScript as given below in an ASP Page. Suppose I have XYZ.asp page. The code in this page goes as shown below....
1
by: Andrew Parsons | last post by:
Hi all, I had a weird issue with trying to use a cookie in a ASCX housed on my web forms and I was wondering if I am missing something. I wanted to use the authenticated cookie for the user...
2
by: Jon Cosby | last post by:
I'm trying to use a cookie to track the customer's running total. Private Sub dgProds_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
5
by: Ryan Ternier | last post by:
Hey! We need a solution for a problem. We're designing a site where users hate... absolutly hate... with a passion to sign in with a user name / password system. They want to sign in once, and...
1
by: onceuponapriori | last post by:
Greetings gents. I'm a Railser working on a django app that needs to do some scraping to gather its data. I need to programatically access a site that requires a username and password. Once I...
1
by: snitu | last post by:
Hello I have a problem with how to use alternate stylesheet in my site home page using cookies. Normal html file is working with out using cookies.But i have to give authority to customer to...
11
by: Raman Pahwa | last post by:
How to store username and password,cookies I want to create cookies in which the text written by anyone in textbox should be stored? I have this code:- <% dim numvisits...
3
by: swetha123 | last post by:
hello, I don't know how to use cookies please help me in this I am using the dream weaver cs4 I designed the navigation bar to my page using dream weaver cs4 navigation bar contains...
0
by: aswal | last post by:
I have a folder "authen" and a file "index.php" in root directory. In folder authen i have created a login.php file with the help of which user can login to the website. The problem is after the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.