How to delete cookie javascript?

Hi, i just try to make cookie in javascript. now i want to delete it if i click end. but i have try and thats not working. please help

test.php

<script type="text/javascript">
function confirm_click()
{
return confirm("Are you sure want to end test ?");
if(confirm==true){
  setCookie('waktux',0,-1);
  else
    false;
}
}
</script>
<script>
  var times = 150;
  var time;
  var go = 0;
  var end = 0;
  
  function init(){
checkCookie()
start();
  }

  function keluar(){
if(end==0){
  setCookie('waktux',time,1);
}else{
  setCookie('waktux',0,-1);
}
  }
  
  function start(){
hour = Math.floor(time/3600);
sisa = time%3600;
minute = Math.floor(sisa/60);
sisa2 = sisa%60
second = sisa2%60;

if(minute < 1 && hour == 0){
  var peringatan = 'style="color:red"';
}

if(second<10){
  detikx = "0"+second;
}else{
  detikx = second;
}

if(minute<10){
  menitx = "0"+minute;
}else{
  menitx = minute;
}

if(hour<10){
  jamx = "0"+hour;
}else{
  jamx = hour;
}

  document.getElementById("divwaktu").innerHTML = '<h4 align="right"'+peringatan+' style="color:#991111;" >time: &nbsp;&nbsp;&nbsp;'+ menitx + ' : ' + detikx + '</h4>'
time --;
if(time>0){
  t = setTimeout("start()",1000);
  go = 1;
}else{
  if(go==1){
    clearTimeout(t);
  }
  end = 1;
  document.getElementById("formulir").submit();
  }
}

  function selesai(){
document.getElementById("formulir").submit();
  }

  function getCookie(c_name){
if (document.cookie.length>0){
  c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1){
      c_start=c_start + c_name.length+1;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
    }
}
return "";
  }

  function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
  }

  function checkCookie(){
waktuy=getCookie('waktux');
if (waktuy!=null && waktuy!=""){
  time = waktuy;
}else{
  time = times;
  setCookie('waktux',times,7);
}
  }
</script>

this is my link:

<li class="men1"><a onclick="return confirm_click();" href="index.php" >Exit</a><strong class="hover"></strong></li>

This post appears to be a duplicate of the thread you’ve posted in this one - Confuse make cookie in Javascript - please be aware that we don’t permit duplicate posting in multiple forums. Can you let me know which one you wish to keep, and I’ll remove the other.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.