0

Please how can i get a username in a text ... i'm using cookies on javascript and i tried that but didn't work

function getCookie(cname) {
   var name = cname + "=";
   var decodedCookie = decodeURIComponent(document.cookie);
   var ca = decodedCookie.split(';');
   for(var i = 0; i < ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0) == ' ') {
         c = c.substring(1);
         if (c.indexOf(name) == 0) {
           return c.substring(name.length, c.length);
         }
      }
 return "";
}
var user=getCookie("username");
alert(user);

I used that to set the cookie :

function setCookie(cname,cvalue) {
  document.cookie = cname + "=" + cvalue;
}

Please how can i acheive that ?

Simon
  • 39
  • 7

0 Answers0