0

I have this piece of code here:

<head>
    <script language="javascript">
        var showMode = 'table-cell';
        if (document.all) showMode='block';

        function toggleVis(btn){
            btn   = document.forms['tcol'].elements[btn];
            cells = document.getElementsByName('t'+btn.name);
            mode = btn.checked ? showMode : 'none';
            for(j = 0; j < cells.length; j++) cells[j].style.display = mode;
        }
    </script>

</head>
<body>
   <h1>Andmete kustutamine</h1>
   <hr>
   <div id="mainbox">
        <form name="tcol" onsubmit="return false">
            <p id="rand">Kuvatavad tulbad:</p>

            <table class="tabl">
                <tr>
                    <td id="nobord"><input type=checkbox name="col1" onclick="toggleVis(this.name)" checked> Osakond</td>
                    <td id="nobord"><input type=checkbox name="col2" onclick="toggleVis(this.name)" checked> Soetusaasta</td>
                    <td id="nobord"><input type=checkbox name="col3" onclick="toggleVis(this.name)" checked> IT Number</td>
                    <td id="nobord"><input type=checkbox name="col4" onclick="toggleVis(this.name)" checked> Tooterühm</td>
                </tr>
                <tr>
                    <td id="nobord"><input type=checkbox name="col5" onclick="toggleVis(this.name)" checked> Mudeli nimetus</td>
                    <td id="nobord"><input type=checkbox name="col6" onclick="toggleVis(this.name)" checked> SN</td>
                    <td id="nobord"><input type=checkbox name="col7" onclick="toggleVis(this.name)" checked> Riigivara nr</td>
                    <td id="nobord"><input type=checkbox name="col8" onclick="toggleVis(this.name)" checked> Inventaari nr</td>
                </tr>
                <td id="nobord"><input type=checkbox name="col9" onclick="toggleVis(this.name)" checked> Maja</td>
                <td id="nobord"><input type=checkbox name="col10" onclick="toggleVis(this.name)" checked> Ruum</td>
                <td id="nobord"><input type=checkbox name="col11" onclick="toggleVis(this.name)" checked> Vastutaja</td>
                <td id="nobord"><input type=checkbox name="col12" onclick="toggleVis(this.name)" checked> Märkus</td>
                <tr>
                    <td id="nobord"><input type=checkbox name="col13" onclick="toggleVis(this.name)" checked> ID</td>
                    <td id="nobord"><input type=checkbox name="col14" onclick="toggleVis(this.name)" checked> Kasutajanimi</td>
                </tr>
            </table>
        </form>

And it's supposed to hide columns once the certain checkbox is toggled. My problem is that whenever I reload the page... the tick from the box disappears and the colum is there again. Is there a way to disable that? Thanks in advance!

2
  • 1
    store your checkbox value in cookie.hide columns using cookie value Commented Feb 27, 2013 at 8:38
  • 4
    use a cookie or the localstorage to save the current state of the checkbox Commented Feb 27, 2013 at 8:39

2 Answers 2

4

You can't retain local javascript values when you refresh the page, so you're going to either have to save the values in HTML5 Local Storage, or create a cookie and store the values in there.

Sign up to request clarification or add additional context in comments.

Comments

0

You can store it in a cookie using javascript or,using php, you can store it inside a $_SESSION value and insert a condition on column.
Example:

<?php if(!isset($_SESSION['display_column'])){ ?>insert html <?php } ?>

If you need to hide multiple colums you can use an array (you can store it always inside a session)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.