step1 and step2 variables are calling the same cookie in Step 3, and Step 2 is over-writing Step 1's cookie... so in Step 3 step1 and step2 both contact step2's data, thus why it is displaying twice.
the format of a cookie is like such:
cookie_name=data that goes in cookie; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=path_to_cookie; domain=domain_cookie_resides_on; secure
expires, path, domain, and secure are all optional.
so to fix this problem, you would need to either create 2 cookies with different names (eg. cookie1, cookie2), or just get the data from step1 when on Step 2, then combine step1 and step2 and resave the cookie, and then just display the data when you get to Step 3.
I found a couple of functions somewhere on the net that have helped me greatly with Javascript cookies...
function getCookie( name )
{
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ';', len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
function setCookie( name, value, expires, path, domain, secure )
{
var today = new Date();
today.setTime( today.getTime() );
if ( expires )
{
expires = (1000 * 60 * 60) * expires;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name+'='+escape( value ) +
( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) +
( ( path ) ? ';path=' + path : '' ) +
( ( domain ) ? ';domain=' + domain : '' ) +
( ( secure ) ? ';secure' : '' );
}
function deleteCookie( name, path, domain )
{
if ( getCookie( name ) ) document.cookie = name + '=' +
( ( path ) ? ';path=' + path : '') +
( ( domain ) ? ';domain=' + domain : '' ) +
';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
getCookie( name ):
gets the data from the named cookie
setCookie( name, value, expires, path, domain, secure ):
creates a new cookie, or over-writes the old cookie
deleteCookie( name, path, domain )
deletes the cookie