www.webdeveloper.com
Results 1 to 6 of 6

Thread: checbox

  1. #1
    Join Date
    Aug 2008
    Posts
    5

    checbox

    I have a checkbox on my site I'm getting the value from the checkbox. But, how can I removed the value from the cookie when checkbox is uncheck. First time using javascript. When the checkbox is checked I get the value of the cookie. I'm using the following to get the value into the cookie from the check box by

    <script type="text/javascript">

    function setCookie(sName,cm) {


    var cValue = GetCookieValue();

    if (cValue == null) {
    document.cookie = sName + "=" + cm;
    }
    else
    {
    document.cookie = sName + "=" + cValue + ',' + cm;
    }


    }

    function GetCookieValue()
    {

    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++)
    {

    var aCrumb = aCookie[i].split("=");
    if (aCrumb[0] == 'Selectedmar')
    return unescape(aCrumb[1]);
    }


    return null;


    }
    //-->
    </script>


    <input type="checkbox" id="check" name="sName" onclick="setCookie('Selectedcm', this.value);" runat="server" />

    Thank you in advanced.

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,410

    Question

    I'm unclear about what you are trying to do.

    In:
    PHP Code:
    <input type="checkbox" id="check" name="sName" onclick="setCookie('Selectedcm', this.value);" runat="server" /> 
    what is the contents of 'this.value'?
    Do you expect it to be anything but 'null'?

  3. #3
    Join Date
    Aug 2008
    Posts
    5
    I was told that 'this.value' was need it because the <input type="checkbox" id="check" name="sName" onclick="setCookie('Selectedcm', this.value);" runat="server" /> is inside a usercontrol. Like I said before I'm getting the value of the cookie. I found a way to removed the cookie but know the problem that I have is that when I unchecked one box all the values inside the cookie are deleted how can I fix that.

    <script type="text/javascript">

    function setCookie(sName,cm) {


    var cValue = GetCookieValue();

    if (cValue == null) {
    document.cookie = sName + "=" + cm;
    }
    else
    {
    document.cookie = sName + "=" + cValue + ',' + cm;
    }


    }

    function GetCookieValue()
    {

    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++)
    {

    var aCrumb = aCookie[i].split("=");
    if (aCrumb[0] == 'Selectedmar')
    return unescape(aCrumb[1]);
    }


    return null;

    }

    function del_cookie(sName) {
    document.cookie = sName +
    '=; expires=Thu, 01-Jan-08 00:00:01 GMT;';
    }

    //-->
    </script>

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,410

    Question

    I don't think you understand my question.

    In the statement:
    PHP Code:
    <input type="checkbox" id="check" name="sName" onclick="setCookie('Selectedcm', this.value);" runat="server" /> 
    I don't see a 'value' of "this" to send.

    Should it be:
    PHP Code:
    <input type="checkbox" id="check" name="sName" value='Some_Checkbox_Value_to_send' 
    onclick="setCookie('Selectedcm', this.value);" runat="server" /> 

  5. #5
    Join Date
    Aug 2008
    Posts
    5
    I’m sitting the Value in the code behind

    CType(control.FindControl("check"), HtmlInputCheckBox).Value = some

    Right now the problem that I have is that if a checked multiple box and unchecked just one all the values that where install in the cookie are deleted.

  6. #6
    Join Date
    Aug 2008
    Posts
    5
    Can some one please help me

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles