Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8137847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:17:54+00:00 2026-06-06T11:17:54+00:00

I still have the problem and i don’t know how to fix it. thanks

  • 0

I still have the problem and i don’t know how to fix it. thanks to the answers given i hava an idea of how it looks, but i don’t know how to make it working.


I have a problem with my javascript checkbox code.

I have a function to hide a div (my other post: javascript, When right div is hidden left div has to be 100% width)

But when i refresh the page the checkbox will be checked again, i read something about cookies but i don’t know how to implement this.

My javascript code:

$(function() {
    $("#foo").on("click",function() {
        if ($(this).is(':checked')) $('#checked-a').show('fast',function() {
            $('#checked-b').css("width","60%");
            $('#checked-a').css("width","38%");
        }) ;
        else $('#checked-a').show('fast',function(){
           $('#checked-b').css("width","100%").show();         
           $('#checked-a').css("width","0%").hide();

        });
    });
});

My html code for the checkbox:

<input type="checkbox" checked="checked" name="foo" id="foo" />

My Div’s:

    <div class="content1" id="checked-b">
    <%= button_to "Zoek", search_index_path, :method => :get, :class => 'contentlinks' %>
    <%= button_to "Print", root_url, :class => 'contentlinks' %>
    <%= button_to "Edit", root_url, :class => 'contentlinks' %>
    <%= button_to "Add", root_url, :class => 'contentlinks' %>
<br>    

<div class="spacing">
    <%= yield %>
</div>

</div>


<div class="content2" id="checked-a">

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:17:56+00:00Added an answer on June 6, 2026 at 11:17 am

    if you don’t want the checkbox to be checked by default use

    <input type="checkbox" name="foo" id="foo" />
    

    instead of

    <input type="checkbox" checked="checked" name="foo" id="foo" />
    

    If you want to check the status of the checkbox when the page first loads, add this bit of JavaScript.

    $(document).ready(function(){
        if ($("#foo").is(':checked')){
            $('#checked-b').css("width","60%");
            $('#checked-a').css("width","38%");
        } else {
            $('#checked-b').css("width","100%");
            $('#checked-a').css("width","0%").hide();
        }
    });
    

    If you want the user’s browser to remember if the status of the “foo” checkbox each time the user visits your site, you likely will need to read up on cookies. Here’s a guide for JS Cookies at w3schools


    Edit

    I’ll make no claims that this works because I haven’t tried it, nor have I ever used cookies myself (but I did re-discover that Google has the answers to basically everything. It’s really quite easy when you give it half an effort)

    $(document).ready(function(){
        if (get_cookie( "fooIsChecked" ) == 1){
            $('#foo').prop("checked", true);
            $('#checked-b').css("width","60%");
            $('#checked-a').css("width","38%");
        } else {
            $('#foo').prop("checked", false);
            $('#checked-b').css("width","100%");
            $('#checked-a').css("width","0%").hide();
        }
        $("#foo").on("click",function() {
            if ($(this).is(':checked')){
                set_cookie( "fooIsChecked", "1", 30 );
                $('#checked-a').show('fast',function() {
                    $('#checked-b').css("width","60%");
                    $('#checked-a').css("width","38%");
                }) ;
            } else {
                set_cookie( "fooIsChecked", "0", 30 );
                $('#checked-a').show('fast',function(){
                    $('#checked-b').css("width","100%").show();         
                    $('#checked-a').css("width","0%").hide();
                });
            }
        });
    });
    
    function set_cookie ( cookie_name, cookie_value, lifespan_in_days, valid_domain ){
        var domain_string = valid_domain ? ("; domain=" + valid_domain) : '' ;
        document.cookie = cookie_name +
            "=" + encodeURIComponent( cookie_value ) +
            "; max-age=" + 60 * 60 * 24 * lifespan_in_days +
            "; path=/" + domain_string;
    }
    
    function get_cookie ( cookie_name ){
        var cookie_string = document.cookie;
        if (cookie_string.length != 0) {
            var cookie_value = cookie_string.match (
                '(^|;)[\s]*' + cookie_name + '=([^;]*)' );
            return decodeURIComponent ( cookie_value[2] ) ;
        }
        return '' ;
    }
    

    Code modified from The Site Wizard

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read the other threads regarding this same problem but I still don't
First thing I know this is repeated question but I don't have problem in
I have a kind of basic (but still unresolved) problem. I'm building a program
I have already made an algorithm for the problem but it still got a
I have a problem and don't know where it is... if I do this
I have pretty much tried everything but still have this same problem. I have
Q: I have the following problem : i don't know what the problem i
I still have a problem with the splash screen. I don't want to use
i still have a problem to develop a convenient app to the user. because
I have this problem again and again... and still have not a satisfactory answer...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.