I'm trying to set multiple cookies in document.cookie, but unfortunately my code shows the cookie value as null and undefined. My code is as belows:
<script>
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
var cookie_string = name + "=" + escape ( value );
if ( exp_y )
{
var expires = new Date ( exp_y, exp_m, exp_d );
cookie_string += "; expires=" + expires.toGMTString();
}
if ( path )
cookie_string += "; path=" + escape ( path );
if ( domain )
cookie_string += "; domain=" + escape ( domain );
if ( secure )
cookie_string += "; secure";
document.cookie = cookie_string;
}
</script>
<script>
alert(setCookie( "username", "Miron" ));
alert(setCookie( "username", "Mirion", 2003, 01, 15 ));
alert(setCookie("username", "John Smith", 2003, 01, 15, "","elated.com", "secure"))
</script>
I technically see no fault in the code. Please tell me where I had gone wrong
setCookiedoes not return a value so you can not call it inalert