getcookie: how to retrieve value of a cookie

Hi,
trouble in the last line in my code:
document.getElementById('Checkbox1').checked = getCookie('Checkbox1');

I am always getting 'true' for the value of my cookie,
so I guess it is just checking if the cookie exists or not.
I actually want the values TRUE or FALSE
I have a checkbox on my form, when I tick it the value is TRUE for getcookie('Checkbox1'))
when I leave it blank, the value is FALSE for getcookie('Checkbox1')

This is my code:
<html>
<head>
<title>TITLE</title>
</head>
<body onload="getCookie('Checkbox1');">                                    
      <Form name="form1">
      Keep opening automatically:
      <input type="checkbox" name="Checkbox1" value="" ONCLICK="setCookie(this.checked);">  
      <a href="#" onclick="alert(getCookie('Checkbox1'))">Get Cookie!</a>
      </Form>
</body>
</html>
<script>
function setCookie(value)
{
    document.cookie= 'Checkbox1=' + value;
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
alert(getCookie('Checkbox1'));
document.getElementById('Checkbox1').checked = getCookie('Checkbox1');
</script>
LVL 1
geertbroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sajuksCommented:
//try this.The value of true and false is a boolean value and not a string value.
<html>
<head>
<title>TITLE</title>
</head>
<body onload="getCookie('Checkbox1');">                              
     <Form name="form1">
     Keep opening automatically:
     <input type="checkbox" name="Checkbox1" value="" ONCLICK="setCookie(this.checked);">  
     <a href="#" onclick="alert(getCookie('Checkbox1'))">Get Cookie!</a>
     </Form>
</body>
</html>
<script>
function setCookie(value)
{
alert( value)
    document.cookie= 'Checkbox1=' + value;
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

ls_string = getCookie('Checkbox1')
if ( ( ls_string == "false")||( ls_string == null))
{

document.getElementById('Checkbox1').checked = false;
}
else
{

document.getElementById('Checkbox1').checked = true;
}
</script>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
geertbroAuthor Commented:
Some extra point for your EXCELLENT solution !
Many many thanx!!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.