Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm trying to set multiple values into a cookie and I'm having trouble figuring out how to create a function for it. I'm setting this up for a customized search result in php where users can select various items with checkboxes.
A cookie is then create whilst the user clicks the checkbox, at the moment I'm using this to create the cookie:
[syntax="javascript"]
function getCookie( name ) {//get cookie name
var start = document.cookie.indexOf( name + "=" ); //variable start
var len = start + name.length + 1; //variable len
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
return null;//if vars do not exists
}
if ( start == -1 ) return null; //if var is negative
var end = document.cookie.indexOf( ";", len ); //end variable
if ( end == -1 ) end = document.cookie.length; //if end is negative
return unescape( document.cookie.substring( len, end ) ); //return cookie
}
function setCookie(name, value)
{
var today = new Date();
var expires_date = new Date( today.getTime() + (24*60*60*1000*60) ); // cookie persist for 60 day
document.cookie = name+"="+escape(value)+";path=/;expires=" + expires_date.toGMTString();
}I haven't created the function which joins the checkbox to the cookie just as yet.
I was wondering if anyone has done anything like this or has any idea on how I could put this together. Any help would be much appreciated.
Also I'm planning to display the selected list with the use of PHP so how hard would it be to display cookies created with JS with PHP?
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]